[gambit-list] (eval (cons func '(1 2))) don't work
    Marc Feeley 
    feeley at iro.umontreal.ca
       
    Mon Aug 20 18:38:16 EDT 2007
    
    
  
On 20-Aug-07, at 5:34 PM, naruto canada wrote:
>>
>> I'm not sure what you tried but Gambit supports a multiple argument
>> apply (the last argument is a list of the remaining arguments.  So:
>>
>>> (apply + '(1 2 3 4))
>> 10
>>> (apply + 1 '(2 3 4))
>> 10
>>> (apply + 1 2 '(3 4))
>> 10
>>> (apply + 1 2 3 '(4))
>> 10
>>> (apply + 1 2 3 4 '())
>> 10
>>
>> Marc
>>
>>
>
> You are right, I had a mismatch of arity. It works now.
> Still, both methods should be equivalent.
In general (apply E1 E2) != (eval (cons E1 E2))
because eval tries to recursively evaluate its argument.  It will try  
to evaluate the **result** of evaluating E1, and all the elements of  
the list **resulting** from the evaluation of E2.  With apply the  
second round of evaluation does not occur.
Note that sometimes there is no difference because
   5 = (eval 5) = (eval (eval 5)) = ...
but in other cases there is a difference because
   car = (eval 'car) != (eval (eval 'car)) != ...
Marc
    
    
More information about the Gambit-list
mailing list