What can you do in LISP that you can't do in Python
Paul Foley
see at below
Thu May 24 05:50:00 EDT 2001
On 24 May 2001 07:58:21 GMT, mikel evins wrote:
> I don't know the answer to the question in the subject line. I'm a fan of
> both LISP and Python, considerably more experienced in LISP than in Python
> (but I've written nontrivial programs in both). But as a fun intellectual
> exercise I thought I'd try to think of a typically LISPy kind of thing that
> I don't know how to do in Python, and see whether someone who knows Python
> better does know how to do it.
> Here's the Common Lisp code:
> (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. I.e., the result won't be easily
predictable. It *may* do something like what you say it does in
interpreted code, if the expansion isn't being cached somewhere; it'll
certainly return constant (but probably not very easily predictable)
values in compiled code. Constant zeros if you just compile code
using this thing in a fresh Lisp image.
--
Qui beneficium dedit, taceat; narret qui accepit -- Seneca
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))
More information about the Python-list
mailing list