Map on the lambda & lambda-macro expressions

Started by Kazimir Majorinc, August 13, 2008, 10:58:44 PM

Previous topic - Next topic

Kazimir Majorinc

> (map quote (lambda(x)(sin x)))

('(x) '(sin x))



So, lambda is lost. The same for lambda-macro.



Map on the function is rarely needed, but if it is I think (lambda'(x)'(sin x)) has more sense than current ('(x)'(sin x)). Alternative is ('lambda'(x)'(sin x)), however, special treatment of the lambda lists in Newlisp seems to be in favour of the (lambda'(x)'(sin x)).
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Kazimir Majorinc

#1
Now I see that there are other such functions, like filter and clean. The most important functions like push, pop, set-nth, reverse, however, respect lambda.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Lutz

#2
lambda in newLISP is not a built-in primitive but a sub-type of the list-type:


> (list? (lambda (x) (+ x x)))
true
> (lambda? (lambda (x) (+ x x)))
true
> (first (lambda (x) (+ x x)))
(x)
> (last (lambda (x) (+ x x)))
(+ x x)
>


A lambda list behaves like a constant, if you evaluate it, it stays the same. This is different from Scheme and CL where lambda lists evaluate to a  function data type and are not accessible as lists anymore.



Because of this, newLISP is more data equals program compared to other Lisps and user defined functions can still be (self)modified after creation.



All destructive functions working on lambda lists will maintain the lambda-list type, but 'map' will treat the lambda-list a normal list and assemble a new non-lambda list.



'append' is left associative for the type and can create new lambda lists and 'cons' is right associative for the type:


> (append (lambda (x)) '(+ x x))
(lambda (x) + x x)
>
> (cons '(x) (lambda (+ x x)))
(lambda (x) (+ x x))
>