From: Adam Warner
Subject: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <pan.2004.01.18.01.11.23.943932@consulting.net.nz>
Hi all,

Consider:
(list 'quote '(a b c)) => '(a b c)
(eval *) => (a b c)

Multiple forms passed to quote cannot be evaluated:
(list 'quote '(a b c) '(d e f)) => (quote (a b c) (d e f))
(eval *) => Wrong number of args to QUOTE

Unquoting a list is less efficient:
(list 'quote '(a b c)) => '(a b c)
(cadr *) => (a b c)


Now if ' was encoded as a CONS (called CONSQUOTE):
(cons 'consquote '(a b c)) => '(a b c)

Illegal quote construction would be instantly discovered:
(cons 'consquote '(a b c) '(d e f)) => Invalid number of arguments

And unquoting a list would be more efficient (less indirection) and an
extra cons of storage would be avoided:
(cdr '(a b c)) => (a b c)


Is encoding ' as a list just an artifact of history or have I missed
something?

Thanks,
Adam

From: Brian Mastenbrook
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <170120042131303608%NOSPAMbmastenbNOSPAM@cs.indiana.edu>
In article <······························@consulting.net.nz>, Adam
Warner <······@consulting.net.nz> wrote:

> Hi all,
> 
> Consider:
> (list 'quote '(a b c)) => '(a b c)
> (eval *) => (a b c)
> 
> Multiple forms passed to quote cannot be evaluated:
> (list 'quote '(a b c) '(d e f)) => (quote (a b c) (d e f))
> (eval *) => Wrong number of args to QUOTE
> 
> Unquoting a list is less efficient:
> (list 'quote '(a b c)) => '(a b c)
> (cadr *) => (a b c)
> 
> 
> Now if ' was encoded as a CONS (called CONSQUOTE):
> (cons 'consquote '(a b c)) => '(a b c)
> 
> Illegal quote construction would be instantly discovered:
> (cons 'consquote '(a b c) '(d e f)) => Invalid number of arguments
> 
> And unquoting a list would be more efficient (less indirection) and an
> extra cons of storage would be avoided:
> (cdr '(a b c)) => (a b c)
> 
> 
> Is encoding ' as a list just an artifact of history or have I missed
> something?

First of all, ' isn't "encoded". It's reader syntax for the special
form QUOTE, and when (QUOTE OBJ) is evaluated, it simply returns OBJ.
As such there's really no such thing in this context as unquoting -
you're looking at unevaluated expressions.

To make the special form work with dotted lists instead of a list would
make it contrary to every other CL special form.

-- 
Brian Mastenbrook
http://www.cs.indiana.edu/~bmastenb/
From: Coby Beck
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <bud7j3$2s08$1@otis.netspace.net.au>
[didn't see Adams post yet]

> In article <······························@consulting.net.nz>, Adam
> Warner <······@consulting.net.nz> wrote:
>
> > Hi all,
> >
> > Consider:
> > (list 'quote '(a b c)) => '(a b c)
> > (eval *) => (a b c)
> >
> > Multiple forms passed to quote cannot be evaluated:
> > (list 'quote '(a b c) '(d e f)) => (quote (a b c) (d e f))
> > (eval *) => Wrong number of args to QUOTE
> >
> > Unquoting a list is less efficient:
> > (list 'quote '(a b c)) => '(a b c)
> > (cadr *) => (a b c)
> >
> >
> > Now if ' was encoded as a CONS (called CONSQUOTE):
> > (cons 'consquote '(a b c)) => '(a b c)
> >
> > Illegal quote construction would be instantly discovered:
> > (cons 'consquote '(a b c) '(d e f)) => Invalid number of arguments
> >
> > And unquoting a list would be more efficient (less indirection) and an
> > extra cons of storage would be avoided:
> > (cdr '(a b c)) => (a b c)
> >
> >
> > Is encoding ' as a list just an artifact of history or have I missed
> > something?

What I'm missing is why you think quote should have such special treatment?
Everything you talk about above applies to any operator that takes more than
one argument.
(list 'zerop 2 3)
(eval *) => wrong number of args for zerop

The great thing about lisp is its uniformity and simplicity.  When you eval
a list, the car is the operator, the cdr is the list of arguments, even if
it is a list of length 1.  I don't want exceptions to that rule to muddy
such clear waters.

-- 
Coby Beck
(remove #\Space "coby 101 @ big pond . com")


> First of all, ' isn't "encoded". It's reader syntax for the special
> form QUOTE, and when (QUOTE OBJ) is evaluated, it simply returns OBJ.
> As such there's really no such thing in this context as unquoting -
> you're looking at unevaluated expressions.
>
> To make the special form work with dotted lists instead of a list would
> make it contrary to every other CL special form.
>
> -- 
> Brian Mastenbrook
> http://www.cs.indiana.edu/~bmastenb/
From: Adam Warner
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <pan.2004.01.18.06.36.57.368777@consulting.net.nz>
Hi Coby Beck,

> What I'm missing is why you think quote should have such special treatment?
> Everything you talk about above applies to any operator that takes more than
> one argument.
> (list 'zerop 2 3)
> (eval *) => wrong number of args for zerop

That's a great point, thanks! Writing (quote . a) would be non-uniform
even if the shorthand notation would disguise it. And I couldn't even use
DEFUN to write the reader macro!

Thanks for answering "have I missed something?" Oh yes.

Regards,
Adam
From: Adam Warner
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <pan.2004.01.18.04.35.31.840765@consulting.net.nz>
Hi Brian Mastenbrook,

Sorry for the loose language. I meant the storage representation for
quoted objects.

> To make the special form work with dotted lists instead of a list would
> make it contrary to every other CL special form.

This is circular reasoning. Plus CL special forms that take two or more
arguments can only be constructed as lists.

What came first, the cons or the list? In Lisp the list has a briefer
notation than the cons (even though a non-empty list must be constructed
of two or more conses) so it's the natural construct to choose, especially
when the necessary number of elements may be uncertain at the design stage.

I see some parallels to association lists:
1. Association lists are accessed contrary to other lists. They're not
even composed of true lists.
2. Association lists provide a more efficient storage representation for
pairs of objects than lists.
3. Association lists can be more efficiently deconstructed into key and
value (using CAR and CDR instead of CAR and the CAR of the CDR).
4. Any attempt to store three or more objects in conses is quickly
detected.

All these benefits would still apply to representing quoted objects as a
CONS with the CAR being the quote symbol and the CDR being the object.
The last point, 4., could be important for macro construction.

Whenever I use CAR and CADR to access all the data in a list I have a
nagging suspicion that I've thrown some data away, especially when I come
back later to check the code. If by definition I should not store more
than a pair of objects a cons is usually the superior choice.

Perhaps the important downside is that one must check for a cons before
blindly trying to access the second element in a what is thought to be
a true list.

Regards,
Adam
From: Kaz Kylheku
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <cf333042.0401181050.558c5478@posting.google.com>
Adam Warner <······@consulting.net.nz> wrote in message news:<······························@consulting.net.nz>...
> And unquoting a list would be more efficient (less indirection) and an
> extra cons of storage would be avoided:
> (cdr '(a b c)) => (a b c)

Sure, but this slight inefficiency only occurs when you process the
read syntax, and when you compile code, not when you actually run it.

> Is encoding ' as a list just an artifact of history or have I missed
> something?

Of course it's an artifact of history. (QUOTE X) existed first. The 'X
shorthand came later.

How the ' is encoded is almost entirely irrelevant; what is helpful is
that there is a standard-required representation that you can rely on.

Lisp would work just as well if a single cons cell had been used as
the target representation of the quote reader instead of a two-cons
list. But the QUOTE operator would have had to be preserved for direct
use.

In other words, you'd need two quotes: (QUOTE X) for direct use, and
the special syntax (CONSQUOTE . X) used as a target language by the '
read macro.

This syntax requires mutated evaluation rules, because (OPERATOR .
ATOM) is invalid except when ATOM is NIL.

Also, it would be harder to explain the ' reader to newbies. :)
From: Kalle Olavi Niemitalo
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <871xpvldtr.fsf@Astalo.kon.iki.fi>
···@ashi.footprints.net (Kaz Kylheku) writes:

> This syntax requires mutated evaluation rules, because (OPERATOR .
> ATOM) is invalid except when ATOM is NIL.

A dotted list is is invalid as a function form or a lambda form.
However, section 3.4.4 explicitly allows dotted lists as macro
forms, provided the macro is written to handle that.

  (defmacro consquote (&rest object)
    `(quote ,object))

Defining CONSQUOTE as a special operator would not require
mutating any existing evaluation rules either, as section
3.1.2.1.2.1 already specifies that evaluation is defined
separately for each special operator.

> Also, it would be harder to explain the ' reader to newbies. :)

I don't think I've ever had to do that.
From: Pascal Bourguignon
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <87smibso2v.fsf@thalassa.informatimago.com>
Adam Warner <······@consulting.net.nz> writes:

> Hi all,
> 
> Consider:
> (list 'quote '(a b c)) => '(a b c)
> (eval *) => (a b c)
> 
> Multiple forms passed to quote cannot be evaluated:
> (list 'quote '(a b c) '(d e f)) => (quote (a b c) (d e f))
> (eval *) => Wrong number of args to QUOTE
> 
> Unquoting a list is less efficient:
> (list 'quote '(a b c)) => '(a b c)
> (cadr *) => (a b c)
> 
> 
> Now if ' was encoded as a CONS (called CONSQUOTE):
> (cons 'consquote '(a b c)) => '(a b c)
> 
> Illegal quote construction would be instantly discovered:
> (cons 'consquote '(a b c) '(d e f)) => Invalid number of arguments
> 
> And unquoting a list would be more efficient (less indirection) and an
> extra cons of storage would be avoided:
> (cdr '(a b c)) => (a b c)
> 
> 
> Is encoding ' as a list just an artifact of history or have I missed
> something?


Note that:
 (cons 'quote '(a b c)) --> (quote a b c)  Oops, several arguments here!


-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
From: Alexander Burger
Subject: Re: Why is ' encoded as a LIST instead of a CONS?
Date: 
Message-ID: <bvntt5$u026p$1@ID-99471.news.uni-berlin.de>
Adam Warner <······@consulting.net.nz> wrote:
> Is encoding ' as a list just an artifact of history or have I missed
> something?

PicoLisp is implemented the way you describe. The read quote macro

   'a 

expands to

   (quote . a)

and

   '(a b c)

expands to

   (quote a b c)

With that, the C-implementation of the quote function is the
shortest (and fastest) of all functions:

   any doQuote(any x) {return cdr(x);}

It simply returns all argument(s) without evaluation.

-- Alex

   Software Lab. Alexander Burger
   Bahnhofstr. 24a, D-86462 Langweid
   ···@software-lab.de, www.software-lab.de, +49 821 9907090