> * In message <3A716089.E6D89FDE@...>
> * On the subject of "[clisp-list] Family of functions"
> * Sent on Fri, 26 Jan 2001 12:33:29 +0100
> * Honorable Francisco Jes=FAs Mart=EDn Mateos <fjesus@...> writes:
>
> I want to build a family of functions, my first attempt was
>=20
> (setq function-set-1
> (loop for i from 0 to 9 collect
> (lambda (x) (list x i))))
(setq function-set-1
(loop for i from 0 to 9 collect
(let ((i i)) (lambda (x) (list x i)))))
should do what you want.
this is because in your version "i" is bound in turn to 0..9 and lambda
gets the binding, so all lambdas have the same "i", so to speak, which
changes values.
in my version, each lambda gets its own "i", bound specifically for it.
this is not a bug, but a subtle intricacy of Common Lisp.
--=20
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/isra=
el>
Read what the Arab leaders say to their people on <http://www.memri.org/&gt;
The paperless office will become a reality soon after the paperless toilet.

On Fri, 26 Jan 2001, Francisco Jes=FAs Mart=EDn Mateos wrote:
> I want to build a family of functions, my first attempt was
>=20
> (setq function-set-1
> (loop for i from 0 to 9 collect
> (lambda (x) (list x i))))
Try:
(setq function-set-1
(loop for i from 0 to 9 collect
(let ((j i))
(lambda (x) (list x j))))
> What's the problem with loop?
In the loop version you were using ten times the same variable, not ten
different variables.
P.

Community

Help

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

I agree to receive quotes, newsletters and other information from sourceforge.net and its partners regarding IT services and products. I understand that I can withdraw my consent at any time. Please refer to our Privacy Policy or Contact Us for more details