Page 1 of 1

Why first lambda expression is args

PostPosted: Mon Jul 06, 2015 8:52 am
by ssqq
I think first lambda expression should is 'lambda:

Code: Select all
> (first (lambda (x y) (+ x y)))
lambda
> (first (fn (x y) (+ x y)))
fn
> 'lambda
lambda
> 'fn
fn
> (cons 'fn '((x y) (+ x y)))
(fn (x y) (+ x y))


Why newLISP use args as first elements of lambda expression?
Why could not quote *lambda* and *fn*?

Re: Why first lambda expression is args

PostPosted: Fri Oct 02, 2015 1:38 pm
by hartrock
ssqq wrote:I think first lambda expression should is 'lambda:

Code: Select all
> (first (lambda (x y) (+ x y)))
lambda
> (first (fn (x y) (+ x y)))
fn
> 'lambda
lambda
> 'fn
fn
> (cons 'fn '((x y) (+ x y)))
(fn (x y) (+ x y))


Why newLISP use args as first elements of lambda expression?
Why could not quote *lambda* and *fn*?

lambda is a property of a list, and not a symbol at its beginning; an example:
Code: Select all
> (set 'li (cons '(x y) (cons '(+ x y) '())))
((x y) (+ x y))
> (first li)
(x y)
> (set 'la (cons '(x y) (cons '(+ x y) '(lambda))))
(lambda (x y) (+ x y))
> (first la)
(x y)
>
-> both list and lambda list having (x y) as first element.
But only the lambda list works as function:
Code: Select all
> (li 3 4)

ERR: invalid list index
> (la 3 4)
7
>

From the manual http://www.newlisp.org/downloads/newlisp_manual.html#fn:
... The fn or lambda word does not exist on its own as a symbol, but indicates a special list type: the lambda list. ...