functional programming and default parameters
ralf.muschall at alphasat.de
Mon Jul 2 12:16:05 CEST 2001
Gareth.McCaughan at pobox.com (Gareth McCaughan) writes:
> (mapcar #'funcall (loop for i upfrom 1 to 5 collecting (lambda () i)))
> ==> (6 6 6 6 6)
This is what I wrote about (in Lisp only lambda and equivalents create
scope, i.e. writing (let ((i i)) ...) into the bove line would work).
Inside the lisp loop, the i is not created over and over, but created
once and then overwritten (which is in turn different from dylan, where
such a loop works). Both effects (non-creation in lisp and creation in
dylan) bite newbies over and over.
What I didn't know was which constructs in python create scope
(I learned from Tim's posting that "for" doesn't - my previous
intuition might have been influenced subconciously by C++).
The situation in python is remotely similar to lisp in that the loop
variable is created only once - just forcing python to create a fresh
scope needs a more verbose hack.
(#Mfuncall (#M(lambda (x) (lambda () x)) (scan-range :below 6)))
> I don't remember reading Ralf's original article, so if that
It might be hard to find from Tim's Posting, since that says
In-Reply-To: <u7k81v6zf2.fsf at hpeesof.asc>
instead of using the "References"-header (my gnus finds it with '^',
but the summary buffer does not use it for threading). I'll include
the reference manually into the header here,
More information about the Python-list