Page 1 of 1

Why is (quote x) different from 'x ?

Posted: Wed May 14, 2008 5:21 pm
by Kazimir Majorinc

Code: Select all

> (println (= ''x '(quote x)))
nil
Is it bug or feature? 9.3.12 version.

Posted: Wed May 14, 2008 5:52 pm
by Lutz
In newLISP quote is a function which must be evaluated:

Code: Select all

> (= '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.

Posted: Wed May 14, 2008 6:51 pm
by cormullion
But '(quote x) is a list:

Code: Select all

>(list? '(quote x))
true

Posted: Wed May 14, 2008 7:26 pm
by rickyboy
Lutz already gave the answer. The following is just a comparative look at the use of quote in some Lisps.

Code: Select all

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

Code: Select all

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)

Code: Select all

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.

Code: Select all

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

Posted: Wed May 14, 2008 8:20 pm
by Kazimir Majorinc
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?)

Posted: Wed May 14, 2008 8:30 pm
by rickyboy
Kazimir Majorinc wrote: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.
Kazimir Majorinc wrote:Is there any advantage of ' (except it is shorter?)
No -- there is no other advantage that I can see.

Posted: Wed May 14, 2008 9:27 pm
by cormullion
Always a pleasure to cross posts with you, Ricky - nice to see you around again. :)

Posted: Wed May 14, 2008 10:38 pm
by Lutz
Kazimir wrote: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.

Code: Select all

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