What can you do in LISP that you can't do in Python
Hannah Schroeter
hannah at schlund.de
Tue May 15 12:29:21 EDT 2001
Hello!
In article <9dreda$oao$1 at saltmine.radix.net>,
Cary O'Brien <cobrien at Radix.Net> wrote:
>[... Common Lisp macros ...]
>I think it is pretty easy to write new control structures in TCL,
>since you can eval a string in the calling context. Like a 12 line
>tcl proc that loops over a SQL result set, binds the columns to
>variables, and runs the "body" of the loop. Is this the same thing?
Nearly. Lisp macros are definitely expanded during file *compilation*,
not in each run of the code.
Imagine something like this:
(dotimes (i 1000000)
(some-macro ...))
Here, the call to (some-macro ...) is expanded *once*, not a million
times.
Also, Lisp macros don't have to deal with the *concrete* syntax,
so a (useless, in practise, just for example purposes) macro for
defining a function of *N* arguments, ignoring all of them and returning
"nil", looks like this:
(defmacro define-useless-function (name n)
(let ((argument-names
(loop for i from 1 to n
collect (intern (format nil "ARG-~d" i)))))
`(defun ,name ,argument-names nil)))
You don't have to produce the *string* "(defun some-fn (ARG-1 ...))",
you produce the AST (abstract syntax tree), so to say.
Kind regards,
Hannah.
More information about the Python-list
mailing list