newLISP Fan Club

Forum => newLISP newS => Topic started by: Kazimir Majorinc on May 14, 2008, 10:21:49 AM

Title: Why is (quote x) different from 'x ?
Post by: Kazimir Majorinc on May 14, 2008, 10:21:49 AM
> (println (= ''x '(quote x)))
nil


Is it bug or feature? 9.3.12 version.
Title:
Post by: Lutz on May 14, 2008, 10:52:00 AM
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.
Title:
Post by: cormullion on May 14, 2008, 11:51:48 AM
But '(quote x) is a list:


>(list? '(quote x))
true
Title:
Post by: rickyboy on May 14, 2008, 12:26:34 PM
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.)
Title:
Post by: Kazimir Majorinc on May 14, 2008, 01:20:43 PM
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?)
Title:
Post by: rickyboy on May 14, 2008, 01:30:48 PM
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.
Title:
Post by: cormullion on May 14, 2008, 02:27:17 PM
Always a pleasure to cross posts with you, Ricky - nice to see you around again. :)
Title:
Post by: Lutz on May 14, 2008, 03:38:17 PM
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
>