Strange reader

Started by steloflute, January 10, 2016, 08:56:08 PM

Previous topic - Next topic

steloflute

I think special processing for lambda and fn is done too early. The reader should preserve the symbols as is.


> 'lambda

ERR: invalid lambda expression : "lambda"
> 'fn

ERR: invalid lambda expression : "fn"
> 'a
a
> (quote lambda)

ERR: invalid lambda expression : " lambda)"
> (fn (x) x)
(lambda (x) x)
> '(fn (x) x)
(lambda (x) x)
> (legal? "fn")
true
> (legal? "lambda")
true
> (sym "fn")
fn

ssqq

#1
I think this is a bug.



symbol table should permit "fn" or "lambda" as name.

TedWalther

#2
This didn't work either, surprised me:


Quote
> (define λ fn)



ERR: invalid lambda expression : " fn)"

> (define λ 'fn)



ERR: invalid lambda expression : "fn)"

> (set 'λ 'fn)



ERR: invalid lambda expression : "fn)"

> (constant 'λ 'fn)



ERR: invalid lambda expression : "fn)"

> (constant 'λ fn)



ERR: invalid lambda expression : " fn)"
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.

Lutz

#3
The keywords lambda, lambda-macro, fn and fn-macro are resolved / translated at a very early stage of the source reading process for speed efficiency reasons. Think of them as being built-in and not re-definable similar to parentheses and quotes, they are part of the syntax.



These keywords translate into a parenthesized-expression attribute. A parenthesized expression is then lambda-executable or lambda-list. As a minimum, you have to include it in parentheses:



> (lambda)
(lambda )
> (lambda-macro)
(lambda-macro )
>


This is also the reason that these keywords are not counted as normal symbols:

> (length (lambda))
0
>


The lambda keyword makes a lambda-list out of a normal list.

steloflute

#4
Hi, Lutz.



Speed efficiency for read? or for eval? If it is for read, then I agree. But if it it not, I suggest putting preprocessing stage between read and eval stages. Then the symbols lambda, lambda-macro, fn and fn-macro can be used in a user land.

ssqq

#5
Now follow expr is ok:



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

> (lambda? (cons (sym "fn")))
nil
;; but get lambda exprssion in dynamically is not ok
> (lambda? (eval (cons (sym "fn"))))
ERR: invalid function : (fn)