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

Started by ssqq, January 07, 2015, 06:10:19 AM

Previous topic - Next topic

ssqq

Following code would throw error:



> 'fn
ERR: invalid lambda expression : "fnn"
> 'lambda
ERR: invalid lambda expression : "lambdan"
> (quote fn)
ERR: invalid lambda expression : " fn)n"
> (quote lambda)
ERR: invalid lambda expression : " lambda)n"


If it is a bug?

rickyboy

#1
Lutz explained why this so, not too long ago here: http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=5&t=4553&p=22482#p22482">http://www.newlispfanclub.alh.net/forum/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.
(λx. x x) (λx. x x)

ssqq

#2
Thanks, I use *lambda?* to check if expression starts with *fn* or *lambda*.
(lambda? '(fn (x) (add x))) ;--> true
to get the symbol of *fn* or *lambda*, could use following code:


(sym "fn") ; --> fn
(sym "lambda") ; --> lambda


then, could check it.


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