novice question about QUOTE and LIST

Discussion of Common Lisp
Post Reply
mikau16
Posts: 1
Joined: Wed Mar 06, 2013 11:52 am

novice question about QUOTE and LIST

Post by mikau16 » Wed Mar 06, 2013 12:05 pm

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?

pjstirling
Posts: 166
Joined: Sun Nov 28, 2010 4:21 pm

Re: novice question about QUOTE and LIST

Post by pjstirling » Sat Mar 09, 2013 1:44 am

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

sylwester
Posts: 133
Joined: Mon Jul 11, 2011 2:53 pm

Re: novice question about QUOTE and LIST

Post by sylwester » Sat Mar 09, 2013 3:14 pm

'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

marcoxa
Posts: 85
Joined: Thu Aug 14, 2008 6:31 pm

Re: novice question about QUOTE and LIST

Post by marcoxa » Mon Mar 11, 2013 8:13 am

Which implementation is this?
Marco Antoniotti

mcheema
Posts: 7
Joined: Mon Nov 05, 2012 3:58 am

Re: novice question about QUOTE and LIST

Post by mcheema » Tue Mar 12, 2013 2:23 pm

^
I get this with ccl64

marcoxa
Posts: 85
Joined: Thu Aug 14, 2008 6:31 pm

Re: novice question about QUOTE and LIST

Post by marcoxa » Thu Mar 14, 2013 8:15 am

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
Marco Antoniotti

Post Reply