Why is (quote x) different from 'x ?

Started by Kazimir Majorinc, May 14, 2008, 10:21:49 AM

Previous topic - Next topic

Kazimir Majorinc

> (println (= ''x '(quote x)))
nil


Is it bug or feature? 9.3.12 version.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Lutz

#1
In newLISP quote is a function which must be evaluated:


> (= 'x (quote x))
true

> (= ''x '(quote x))
nil
>

> (= ''x (quote 'x))
true
>


As the quote is quoted using the ' apostrophe in the second example it does not get evaluated. The third works again because the verbal quote on the ouside gets evaluated.

cormullion

#2
But '(quote x) is a list:


>(list? '(quote x))
true

rickyboy

#3
Lutz already gave the answer.  The following is just a comparative look at the use of quote in some Lisps.


newLISP v.9.3.11 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.

> (= 'x (quote x))
true
> (= ''x '(quote x))
nil
> (quote x)
x
> '(quote x)
(quote x)
> (quote (quote x))
(quote x)
> 'x
x
> ''x
'x


Welcome to MzScheme version 360, Copyright (c) 2004-2006 PLT Scheme Inc.

> (equal? 'x (quote x))
#t
> (equal? ''x '(quote x))
#t
> (quote x)
x
> '(quote x)
(quote x)
> (quote (quote x))
(quote x)
> 'x
x
> ''x
(quote x)


This is SBCL 1.0.6, an implementation of ANSI Common Lisp.

* (equal 'x (quote x))
T
* (equal ''x '(quote x))
T
* (quote x)
X
* '(quote x)
'X
* (quote (quote x))
'X
* 'x
X
* ''x
'X

Telling are the different values yielded by the last expression in the each session, namely that of expression ''x.  Clearly, quote and ' are different animals in newLISP.  In Scheme and Common Lisp, they appear to be equivalent.  (SBCL always outputs the shorthand in the REPL session, i.e. any reduction to (quote x) will always be rendered as 'x.)



Another way to look at the difference between '(quote x) and ''x in newLISP:



In newLISP, ''x is a quote, but '(quote x) is NOT a quote, it's a list.
newLISP v.9.3.11 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.

> (quote? ''x)
true
> (quote? '(quote x))
nil
> (list? '(quote x))
true

This is just a consequence of what Lutz said: "In newLISP quote is a function which must be evaluated."



(Sorry, cormullion -- I was writing this as you were posting.)
(λx. x x) (λx. x x)

Kazimir Majorinc

#4
OK, these two are different in Newlisp.



It seems that (quote <expr>) has advantages, because it is list, and it can be analyzed, while '<expr> is not a list, and it must be evaluated first, to get rid of quote and then analyzed. Is it right?



Is there any advantage of ' (except it is shorter?)
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

rickyboy

#5
Quote from: "Kazimir Majorinc"It seems that (quote <expr>) has advantages, because it is list, and it can be analyzed, while '<expr> is not a list, and it must be evaluated first, to get rid of quote and then analyzed. Is it right?

Yes, as long as we bear in mind that anything we type in the REPL is subject to one round of evaluation.


Quote from: "Kazimir Majorinc"Is there any advantage of ' (except it is shorter?)

No -- there is no other advantage that I can see.
(λx. x x) (λx. x x)

cormullion

#6
Always a pleasure to cross posts with you, Ricky - nice to see you around again. :)

Lutz

#7
Quote from: "Kazimir"Is there any advantage of ' (except it is shorter?)


Its also more than double as fast to process, because it gets pre-compiled during load/read.


> (time 'x 1000000)
25
> (time (quote x) 1000000)
65
>