What can you do in LISP that you can't do in Python

Gareth McCaughan Gareth.McCaughan at pobox.com
Thu May 24 17:03:25 EDT 2001

Paul Foley wrote:

[Mikel Evins:]
> > (let* ((count 0)
> >        (incrementer #'(lambda () (setq count (1+ count)))))
> >   (defmacro counting-setq (var val)
> >     `(progn
> >        (funcall ,incrementer)
> >        (setq ,var ,val)
> >        ,count)))
> > What it does is this: it defines a new version of SETQ called
> > 'counting-setq'. This new operation does the same thing that SETQ does: it
> > sets the value of a variable. But it does something else, too: it counts how
> > many times you call it and saves the current count in a variable that nobody
> > but counting-setq can see or affect. When it sets a variable it increments
> > the current count and then returns it.
> No it doesn't; it returns the number of times it got called prior to
> this particular expansion.

Er, no. The incrementer gets called by the expanded code,
not by the macro expander.

    (counting-setq foo 1)


      (funcall incrementer)
      (setq foo 1)

(modulo symbol capture). The incrementing happens at runtime.
The mistake you said Mikel was making is a common one, but
he didn't make it. :-)

Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc

More information about the Python-list mailing list