Expression | Value | (let* ((ttl "My Document")
(bdy (list 'p "A paragraph"))
(doc
(list 'html
(list 'head
(list 'title ttl))
(list 'body bdy)))
)
(render (eval doc))) | <html>
<head>
<title>My Document</title>
</head>
<body>
<p>A paragraph</p>
</body>
</html> | (let* ((ttl "My Document")
(bdy (list 'p "A paragraph"))
(doc
`(html
(head (title ,ttl))
(body ,bdy))))
(render (eval doc))) | <html>
<head>
<title>My Document</title>
</head>
<body>
<p>A paragraph</p>
</body>
</html> | (+ 1 2 3 4) | 10 | (+ (list 1 2 3 4)) | Error: + expects argument of type number;
given (1 2 3 4) | (apply + (list 1 2 3 4)) | 10 |
| | An illustration of eval and apply.
In the first two rows we construct a list structure of
the usual html , head , title , and body HTML mirror functions.
In the first row, the list structure is made by the list function.
In the second row, we use the convenient backquote (semiquote) facility.
In both cases we get the same result.
The last three rows illustrate the use of apply . apply is handy in the
cases where the parameters of a function is already organized in a list.
What it interesting in our current context, however, is that apply is really
an implementation primitive of Scheme, which is made available in the language
itself.
|