全部文本 #2122741 原始 编辑

Anonymous

公开 text v1 · 不可变
·已发布 2012-02-29 06:18 UTC
渲染后的文本正文
(mapcar #'(lambda ( x y z) (list x z))
'(lambda (a b) (cons a b))
'(1 2 3)
'(list quote z))

mapcar: choose the first element in each list and call the function "#......"
The mapcar will stop as there is no more element in the list to execute. 
It will also stop when there is uneven element. 
For example '(1 2 3) '(4 5). It will execute for (1 4) and (2 5), but not (3), since its uneven.

so in this case function is (lambda (x y z) (list x z))

The list is (lambda (a b) (cons a b)), (1 2 3), (list quote z). total 3 list.

It will choose the element of each list and call the function to execute it.

Since the function is lambda...
lambda is a nameless function like you said, and (x y z) is the parameter, (list x z) is the function.
so there is 3 variable in the parameter, it takes 3 argument. 



The function is this... (lambda (x y z) (list x z))

the first time it execute will take out "lambda" "1" "list" from each list
so it look like  
(lambda ('lambda '1 'list) (list 'lambda 'list))
so it becomes (lambda list)


the second time it execute will take out "(a b)" "2" "quote" from each list
(lambda ('(a b) '2 'quote) (list '(a b) 'quote))
so it becomes ((a b) quote)


the third time it execute will take out "(cons a b)" "3" "z" from each list
(lambda ('(cons a b) '3 'z) (list '(cons a b) 'z))
so it becomes ((cons a b) z)


Since it will return a big list, back it would be ((lambda list) ((a b) quote) ((cons a b) z))