Strange reader

For the Compleat Fan
Locked
steloflute
Posts: 13
Joined: Tue Nov 06, 2012 4:02 pm
Contact:

Strange reader

Post by steloflute »

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

Code: Select all

> '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
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: Strange reader

Post by ssqq »

I think this is a bug.

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

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: Strange reader

Post by TedWalther »

This didn't work either, surprised me:
> (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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Strange reader

Post by Lutz »

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:

Code: Select all

> (lambda)
(lambda )
> (lambda-macro)
(lambda-macro )
> 
This is also the reason that these keywords are not counted as normal symbols:

Code: Select all

> (length (lambda))
0
>
The lambda keyword makes a lambda-list out of a normal list.

steloflute
Posts: 13
Joined: Tue Nov 06, 2012 4:02 pm
Contact:

Re: Strange reader

Post by steloflute »

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
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: Strange reader

Post by ssqq »

Now follow expr is ok:

Code: Select all

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


Locked