This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ((cadr lst) (car lst) (caddr lst)) Won't work


Or equivalently, `(1 ,+ 2) (i.e. instead of QUOTE, use QUASIQUOTE /
UNQUOTE):

#|kawa:1|# '(1 + 2)
(1 + 2)
#|kawa:2|# (list 1 + 2)
(1 #<procedure +> 2)
#|kawa:3|# `(1 ,+ 2)
(1 #<procedure +> 2)
#|kawa:4|# (quasiquote (1 (unquote +) 2))
(1 #<procedure +> 2)

But really, it depends upon the intent: do you want the list to contain
the (self-evaluating) integers 1 and 2 and the *procedure* named +, or
do you want it to contain the numbers and the *symbol* +, which you then
must explicitly evaluate later?

Note the difference here:

#|kawa:1|# (define lst1 (list 1 + 2))
#|kawa:2|# (define lst2 '(1 + 2))
#|kawa:3|# (define + -)
#|kawa:4|# ((cadr lst1) (car lst1) (caddr lst1))
3
#|kawa:5|# ((eval (cadr lst2)) (car lst2) (caddr lst2))
-1
#|kawa:6|# (eval (cadr lst2))
#<procedure ->
#|kawa:7|# (eval (cadr lst2) (kawa.standard.Scheme:builtin))
#<procedure +>

If you store the symbol, then you're at the mercy of the environment in
play when you evaluate it later (unless you specify the environment to
use in the call to eval).  Depending upon your goal, that may be a
problem, or it may be exactly what you want.

-J

On Jun 13, 2013, at 6:23 AM, Charles Turner <chturne@gmail.com> wrote:

> You could also do this without having to use EVAL by writing (list 1 +
> 2) instead of '(1 + 2), looked like you perhaps misunderstood the
> QUOTE special form.
> 
> I attach a patch that cleans up the error message.
> 
> Charles.
> 
> On 13 June 2013 08:12, Per Bothner <per@bothner.com> wrote:
>> On 06/12/2013 06:18 PM, Morven Sun wrote:
>>> 
>>> After I defined (define lst '(1 + 2)),
>>> ((cadr lst) (car lst) (caddr lst)) would not work as (+ 1 2), but
>>> gives the error msg:
>>> Argument '+' to 'apply-to-args' has wrong type
>> 
>> 
>> Note the actual error message is:
>> 
>> Argument  '+' to 'apply-to-args' has wrong type (gnu.mapping.SimpleSymbol)
>> (expected: procedure)
>> 
>> This should have given you a hint as to the problem.
>> True - the raw Java classname "gnu.mapping.SimpleSymbol" is not
>> as obvious as I'd like.  I'm considering defining a new type
>> alias simple-symbol for SimpleSymbol, which would improve the
>> error message to:
>> 
>> Argument  '+' to 'apply-to-args' has wrong type (simple-ymbol) (expected:
>> procedure)
>> --
>>        --Per Bothner
>> per@bothner.com   http://per.bothner.com/
> <simple_symbol.patch>

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]