Page 1 of 1

*(quote fn) or (quote lambda)* error

Posted: Wed Jan 07, 2015 2:10 pm
by ssqq
Following code would throw error:

Code: Select all

> 'fn
ERR: invalid lambda expression : "fn\n"
> 'lambda
ERR: invalid lambda expression : "lambda\n"
> (quote fn)
ERR: invalid lambda expression : " fn)\n"
> (quote lambda)
ERR: invalid lambda expression : " lambda)\n"
If it is a bug?

Re: *(quote fn) or (quote lambda)* error

Posted: Wed Jan 07, 2015 5:48 pm
by rickyboy
Lutz explained why this so, not too long ago here: viewtopic.php?f=5&t=4553&p=22482#p22482

In short, fn and lambda cannot be symbols in the sense you are using them. If you are trying to build newLISP lambdas in your macro code, then follow Lutz's advice in the link above.

Re: *(quote fn) or (quote lambda)* error

Posted: Thu Jan 08, 2015 12:53 am
by ssqq
Thanks, I use *lambda?* to check if expression starts with *fn* or *lambda*.

Code: Select all

(lambda? '(fn (x) (add x))) ;--> true
to get the symbol of *fn* or *lambda*, could use following code:

Code: Select all

(sym "fn") ; --> fn
(sym "lambda") ; --> lambda
then, could check it.

Code: Select all

> > (list 1 (sym "lambda") (sym "fn"))
(1 lambda fn)
> (= (sym "fn") (last (list 1 (sym "lambda") (sym "fn"))))
true
> (= (sym "lambda") (nth 1 (list 1 (sym "lambda") (sym "fn"))))
true