This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

novice question about QUOTE and LIST

6 posts · 6409 views

The following sequence of entries and results make sense to me up until the last one:
>>(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:
>>(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

(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

'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)
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p

Re: novice question about QUOTE and LIST

Which implementation is this?
Marco Antoniotti

Re: novice question about QUOTE and LIST

^
I get this with ccl64

Re: novice question about QUOTE and LIST

It appears that the printer of CCL is set to print anything like
(quote <x>)
as
'<x>
It really does not matter as the reader treats them appropriately.

MA
Marco Antoniotti