Map on the lambda & lambda-macro expressions

Notices and updates
Locked
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Map on the lambda & lambda-macro expressions

Post by 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)).

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Code: Select all

> (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:

Code: Select all

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

Locked