Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

convert a list into a function

1 view
Skip to first unread message

Matt Thompson

unread,
Dec 15, 2001, 2:15:35 PM12/15/01
to
What I would like to do is create a function from a list, I have tried
the following code:

((lambda (x y z) ((lambda (x) y)z)) x x 2)

which would make a function that returns its input (the identity
function), which is 2 in this case. And the compiler doesn't like it.
Can anyone help here?
Thanks,
Matt

Barry Margolin

unread,
Dec 19, 2001, 7:38:28 PM12/19/01
to
In article <71f3b43a.0112...@posting.google.com>,

Matt Thompson <ma6...@bath.ac.uk> wrote:
>What I would like to do is create a function from a list, I have tried
>the following code:
>
>((lambda (x y z) ((lambda (x) y) z)) x x 2)

>
>which would make a function that returns its input (the identity
>function), which is 2 in this case. And the compiler doesn't like it.
>Can anyone help here?

You're calling the outer lambda expression with X in the parameter list,
but you've probably never assigned that variable.

I've translated your code to the more common LET syntax:

(let ((x x)
(y x)
(z 2))
(let ((x z))
y))

Now it should be more obvious that there's something wrong with the way you
initialize X and Y, using the uninitialized X.

The other strange thing about your functions is that you never actually use
the variable X. And the only thing you use Z for is to bind the inner X,
but then you never use that, either.

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

lin8080

unread,
Dec 30, 2001, 4:29:43 AM12/30/01
to
Matt Thompson schrieb:

; build a list - maybe out of an array?
(setq aa (list (quote setq) (quote a) '(+ 8 9)))
; this is same as: (setq a (+ 8 9))
aa
; should print 17

bye
stefan

Coby Beck

unread,
Dec 30, 2001, 11:19:39 PM12/30/01
to

"lin8080" <lin...@freenet.de> wrote in message
news:3C2EDE87...@freenet.de...

> ; build a list - maybe out of an array?
> (setq aa (list (quote setq) (quote a) '(+ 8 9)))
> ; this is same as: (setq a (+ 8 9))
> aa
> ; should print 17
>

will return (setq a (+ 8 9))
You would have to (eval aa) to get 17

--
Coby
(remove #\space "coby . beck @ opentechgroup . com")


lin8080

unread,
Dec 31, 2001, 6:52:51 AM12/31/01
to
Coby Beck schrieb:

> "lin8080" <lin...@freenet.de> wrote in message
> news:3C2EDE87...@freenet.de...
> > ; build a list - maybe out of an array?
> > (setq aa (list (quote setq) (quote a) '(+ 8 9)))
> > ; this is same as: (setq a (+ 8 9))
> > aa
> > ; should print 17

> will return (setq a (+ 8 9))
> You would have to (eval aa) to get 17

Yes. I forgot it.
I used this method in a fuzzy like test programm. It takes long case
lists but with CL it is very fast :)

bye
stefan

0 new messages