Page 1 of 1

novice question about QUOTE and LIST

Posted: Wed Mar 06, 2013 12:05 pm
by mikau16
The following sequence of entries and results make sense to me up until the last one:

Code: Select all

>>(list 1 2 3 'quote 4 5 6)

(1 2 3 QUOTE 4 5 6)


>>(list 1 2 3 'quote )

(1 2 3 QUOTE)

>>(list 'quote 4 5 6)

(QUOTE 4 5 6)

>>(list 1 'quote)

(1 QUOTE)

>>(list 'quote 1)

'1
Why didn't the last one return "(QUOTE 1)"?

My guess was maybe Lisp tries to evaluate the list if the first parameter is a function, macro, or special form, so I tried this:

Code: Select all

>>(list 'setq 'x 5)

(SETQ X 5)

>>(list '+ 1 2)

(+ 1 2)

>>(list 'if t 1 2)

(IF T 1 2)

Can someone explain to me why (list 'quote 1) is treated differently and how it produces '1?

Re: novice question about QUOTE and LIST

Posted: Sat Mar 09, 2013 1:44 am
by pjstirling
(LIST 'QUOTE 1) is being evaluated to the list (QUOTE 1), and then that is printed, and one of the default print rules is that any value of the form (QUOTE x) should be printed 'x.

You can tell that (LIST 'QUOTE 1) is still a list by using REST, (REST '1) is an error, while (REST (LIST 'QUOTE 1)) is (1)

Re: novice question about QUOTE and LIST

Posted: Sat Mar 09, 2013 3:14 pm
by sylwester
'x is just an abbreviation for (quote x). The first LISPs didn't have such abbreviation and when they did ''x would return (quote x). Many (but not all) LISPs today choose to print 'x since it is a simpler visual representation of (quote x).

When you wrote (list 'quote 1), in earlier lisps you would have had to write (list (quote quote) 1)

Re: novice question about QUOTE and LIST

Posted: Mon Mar 11, 2013 8:13 am
by marcoxa
Which implementation is this?

Re: novice question about QUOTE and LIST

Posted: Tue Mar 12, 2013 2:23 pm
by mcheema
^
I get this with ccl64

Re: novice question about QUOTE and LIST

Posted: Thu Mar 14, 2013 8:15 am
by marcoxa
It appears that the printer of CCL is set to print anything like

Code: Select all

(quote <x>)
as

Code: Select all

'<x>
It really does not matter as the reader treats them appropriately.

MA