Strange reader

For the Compleat Fan

Strange reader

Postby steloflute » Mon Jan 11, 2016 4:56 am

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
steloflute
 
Posts: 13
Joined: Tue Nov 06, 2012 4:02 pm

Re: Strange reader

Postby ssqq » Wed Jul 06, 2016 4:35 am

I think this is a bug.

symbol table should permit "fn" or "lambda" as name.
ssqq
 
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: Strange reader

Postby TedWalther » Thu Jul 07, 2016 9:18 am

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.
TedWalther
 
Posts: 602
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

Re: Strange reader

Postby Lutz » Thu Jul 07, 2016 5:49 pm

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.
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: Strange reader

Postby steloflute » Wed Aug 31, 2016 8:50 am

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.
steloflute
 
Posts: 13
Joined: Tue Nov 06, 2012 4:02 pm

Re: Strange reader

Postby ssqq » Sat Sep 03, 2016 4:00 am

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)

ssqq
 
Posts: 88
Joined: Sun May 04, 2014 12:49 pm


Return to Anything else we might add?

Who is online

Users browsing this forum: No registered users and 3 guests

cron