[plt-scheme] abstractions...

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Oct 5 19:56:07 EDT 2005

Jens Axel Søgaard wrote:
> Hi geb a wrote:
> 
>> Hello,
>>
>> Can someone tell me why the two scheme expression
>> below are equivalent?  I do not understand where map
>> gets its function!  Thank you for your help ahead of
>> time!
>>
>> (apply
>>  map
>>  (list
>>   list
>>   (list 1 2 3 4)
>>   (list 5 6 7 8)
>>   (list 7 8 9 0)))
>>
>>
>> (list  (list 1 5 7)
>>  (list 2 6 8)
>>  (list 3 7 9)
>>  (list 4 8 0))
> 
> 
> 
> (apply f (list 1 2 3))        = (f 1 2 3)
> (apply f (list list 1 2 3))   = (f list 1 2 3)
> (apply map (list list 1 2 3)) = (map list 1 2 3)
>                               => '((1) (2) (3))
> 

Oops - I forgot a (list ...):

 > (apply map (list list 1 2 3)) = (map list 1 2 3)

This part is ok, but evaluating (map list 1 2 3) will give an error,
since map expects two arguments.

A better example is

  (apply map (list list (list 1 2 3))) = (map list (list 1 2 3))
                                       => '((1) (2) (3))

To see which list is which, here are the same expression
with indices:

  (apply map (list list_1 (list_2 1 2 3))) = (map list_1 (list_2 1 2 3))
                                           => '((1) (2) (3))


-- 
Jens Axel Søgaard




Posted on the users mailing list.