A
atbusbook
macros are sort of like c macros but more powerful. they are the
manafestation of treating code like data. lisp code is just a textual
representation of a data structure that is the list. this means that
you can manipulate code to emulate structured controll constructs and
elemanate boilerplate code. to show you the power of a macro heer is a
while loop
<code>
(defmacro while (test &body body)
`(do ()
((not ,test))
,@body)
</code>
Another one would be untill
<code>
(defmacro untill (test &body body)
`(while (not ,test) ,@body))
</code>
wich is defined on top of while
another test to wead out programers would be lisp stile macros because
of variable capture
and other perls of the macro world. but higenic macros can not have the
power of true macros
i also hear you talk about introspection. in lisp you use eval list
lets define a sum function to show you
<code>
(defun sum (lst)
(eval (append '(+) lst)))
</code>
another example would be this
<code>
(loop (print (eval (read))))
</code>
this is an interactive top level in 1 line
another use is for calling of functions
<code>
(defvar cmds `('foo ,(lambda () (format t "hello world")))
(funcall (getf cmds (read-from-string (read-line))))
</code>
of corse no error checking for comas and other things that could crash
the program
manafestation of treating code like data. lisp code is just a textual
representation of a data structure that is the list. this means that
you can manipulate code to emulate structured controll constructs and
elemanate boilerplate code. to show you the power of a macro heer is a
while loop
<code>
(defmacro while (test &body body)
`(do ()
((not ,test))
,@body)
</code>
Another one would be untill
<code>
(defmacro untill (test &body body)
`(while (not ,test) ,@body))
</code>
wich is defined on top of while
another test to wead out programers would be lisp stile macros because
of variable capture
and other perls of the macro world. but higenic macros can not have the
power of true macros
i also hear you talk about introspection. in lisp you use eval list
lets define a sum function to show you
<code>
(defun sum (lst)
(eval (append '(+) lst)))
</code>
another example would be this
<code>
(loop (print (eval (read))))
</code>
this is an interactive top level in 1 line
another use is for calling of functions
<code>
(defvar cmds `('foo ,(lambda () (format t "hello world")))
(funcall (getf cmds (read-from-string (read-line))))
</code>
of corse no error checking for comas and other things that could crash
the program