[plt-scheme] Lambda in a list... am I doing something wrong?
Its because you have
>> (lambda () (display "test")). Its just a function here.
Instead if you have
>> ((lambda () (display "test"))), you will get back "test".
My guess is that the return type of display is void. So you will not get back a list of strings by doing what you are doing.
Hari
----- Original Message -----
From: "Jordan Johnson" <jmj at fellowhuman.com>
To: krhari at ccs.neu.edu
Cc: plt-scheme at list.cs.brown.edu
Sent: Monday, October 19, 2009 11:21:23 PM GMT -05:00 US/Canada Eastern
Subject: Re: [plt-scheme] Lambda in a list... am I doing something wrong?
That's not the only issue here, though; the original code had the
lambda inside a quoted list, so the lambda was never evaluated.
Best,
Jordan
On Oct 19, 2009, at 7:50 PM, krhari at ccs.neu.edu wrote:
> Hi,
>
> If I am not wrong, cdr returns a list. So when you have ((cdr (car
> commands))), it will give you ((list your-lambda)). So if you want
> just your function, try ((car (cdr (car commands)))). You might get
> your desired result ("test").
>
> Hari
>
> ----- Original Message -----
> From: "Jon Rafkind" <rafkind at cs.utah.edu>
> To: "Timothy McDowell" <tmcdowell at gmail.com>
> Cc: plt-scheme at list.cs.brown.edu
> Sent: Monday, October 19, 2009 7:43:30 PM GMT -05:00 US/Canada Eastern
> Subject: Re: [plt-scheme] Lambda in a list... am I doing something
> wrong?
>
> Timothy McDowell wrote:
>> I'm trying to write a little interactive fiction, and I have a
>> setup like
>> this:
>> (define commands
>> '(
>> ("look" (lambda () (display "test")))))
>>
>>
>
> Try (define commands (list (list "look" (lambda () (display
> "test")))))
>
>> The response I get from trying ((cdr (car commands))):
>> procedure application: expected procedure, given: ((lambda ()
>> (display
>> "test"))) (no arguments)
>>
>> Can someone explain to me what I am doing wrong?
>>
>> -- Thanks,
>> --Timothy.
>>
>>
>> ---
>> ---------------------------------------------------------------------
>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme