Why is (quote x) different from 'x ?

Notices and updates
Locked
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Why is (quote x) different from 'x ?

Post by Kazimir Majorinc »

Code: Select all

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

But '(quote x) is a list:

Code: Select all

>(list? '(quote x))
true

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post 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.)
(λx. x x) (λx. x x)

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post 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?)

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post 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.
(λx. x x) (λx. x x)

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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
> 

Locked