From: Mark Carroll
Subject: 'function cons question
Date: 
Message-ID: <Vdg*oIw6n@news.chiark.greenend.org.uk>
I'm stuck with using some Allegro application image for something. It
has the interesting behaviour:

lisp: (cons 'some-symbol '("a string"))
(SOME-SYMBOL "a string")
lisp: (cons 'function '("a string"))
#'"a string"
lisp: 

Anyone any ideas how to prepend a list with the symbol FUNCTION?

Thanks. (-:

-- Mark

From: Mark Carroll
Subject: Re: 'function cons question
Date: 
Message-ID: <Twi*IPw6n@news.chiark.greenend.org.uk>
In article <·········@news.chiark.greenend.org.uk>,
Mark Carroll  <·····@chiark.greenend.org.uk> wrote:
(snip)
>#'"a string"
(snip)
>Anyone any ideas how to prepend a list with the symbol FUNCTION?
(snip)

Whoops - it turns out that this _is_ in fact a list of the form
'(FUNCTION "a string"). At least, it behaves in exactly the same
way. How bizarre. (-: Wonder which other ones I have to watch out for.

-- Mark
From: Marco Antoniotti
Subject: Re: 'function cons question
Date: 
Message-ID: <lwk8re6ydm.fsf@copernico.parades.rm.cnr.it>
Mark Carroll <·····@chiark.greenend.org.uk> writes:

> In article <·········@news.chiark.greenend.org.uk>,
> Mark Carroll  <·····@chiark.greenend.org.uk> wrote:
> (snip)
> >#'"a string"
> (snip)
> >Anyone any ideas how to prepend a list with the symbol FUNCTION?
> (snip)
> 
> Whoops - it turns out that this _is_ in fact a list of the form
> '(FUNCTION "a string"). At least, it behaves in exactly the same
> way. How bizarre. (-: Wonder which other ones I have to watch out for.

It is not bizarre once you take into account the behavior of the
Common Lisp printer.  (almost like the 'toString' methods in Java).

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Kent M Pitman
Subject: Re: 'function cons question
Date: 
Message-ID: <sfwwvvdwnqp.fsf@world.std.com>
Marco Antoniotti <·······@copernico.parades.rm.cnr.it> writes:

> Mark Carroll <·····@chiark.greenend.org.uk> writes:
> 
> > In article <·········@news.chiark.greenend.org.uk>,
> > Mark Carroll  <·····@chiark.greenend.org.uk> wrote:
> > (snip)
> > >#'"a string"
> > (snip)
> > >Anyone any ideas how to prepend a list with the symbol FUNCTION?
> > (snip)
> > 
> > Whoops - it turns out that this _is_ in fact a list of the form
> > '(FUNCTION "a string"). At least, it behaves in exactly the same
> > way. How bizarre. (-: Wonder which other ones I have to watch out for.
> 
> It is not bizarre once you take into account the behavior of the
> Common Lisp printer.  (almost like the 'toString' methods in Java).

It's weird to look at but it causes no actual problem for #'"foo".
The printer for your system could be taught not to use this shorthand
when the form was not plausibly a function, though; send a bug report.
From: Rainer Joswig
Subject: Re: 'function cons question
Date: 
Message-ID: <joswig-0208991623550001@pbg3.lavielle.com>
In article <·········@news.chiark.greenend.org.uk>, Mark Carroll <·····@chiark.greenend.org.uk> wrote:

> I'm stuck with using some Allegro application image for something. It
> has the interesting behaviour:
> 
> lisp: (cons 'some-symbol '("a string"))
> (SOME-SYMBOL "a string")
> lisp: (cons 'function '("a string"))
> #'"a string"
> lisp: 
> 
> Anyone any ideas how to prepend a list with the symbol FUNCTION?

You did it. 

It is just printed differently.
There is a difference between an internal
representation and what is being printed.


Hmm, in MCL I can set

(setf *print-abbreviate-quote* nil)

and it prints as you expect.
I don't know how you get around this
in other Lisps. Anyone?
From: Mark Carroll
Subject: Re: 'function cons question
Date: 
Message-ID: <ftx*IPB6n@news.chiark.greenend.org.uk>
In article <·······················@pbg3.lavielle.com>,
Rainer Joswig <······@lavielle.com> wrote:
(snip)
>Hmm, in MCL I can set
>
>(setf *print-abbreviate-quote* nil)
>
>and it prints as you expect.
>I don't know how you get around this
>in other Lisps. Anyone?

Setting *print-pretty* to nil seems to do the trick. (-:

-- Mark
From: Rainer Joswig
Subject: Re: 'function cons question
Date: 
Message-ID: <joswig-0408991125120001@pbg3.lavielle.com>
In article <·········@news.chiark.greenend.org.uk>, Mark Carroll <·····@chiark.greenend.org.uk> wrote:

> In article <·······················@pbg3.lavielle.com>,
> Rainer Joswig <······@lavielle.com> wrote:
> (snip)
> >Hmm, in MCL I can set
> >
> >(setf *print-abbreviate-quote* nil)
> >
> >and it prints as you expect.
> >I don't know how you get around this
> >in other Lisps. Anyone?
> 
> Setting *print-pretty* to nil seems to do the trick. (-:

Portably?
From: Mark Carroll
Subject: Re: 'function cons question
Date: 
Message-ID: <gJu*nFH6n@news.chiark.greenend.org.uk>
In article <·······················@pbg3.lavielle.com>,
Rainer Joswig <······@lavielle.com> wrote:
>In article <·········@news.chiark.greenend.org.uk>, Mark Carroll <·····@chiark.greenend.org.uk> wrote:
(snip)
>> Setting *print-pretty* to nil seems to do the trick. (-:
>
>Portably?

Reasonably so AFAICT, but nothing actually stops working if it fails,
fortunately. Do you have any better ideas? (-:

-- Mark
From: Pierre R. Mai
Subject: Re: 'function cons question
Date: 
Message-ID: <873dxz7buk.fsf@orion.dent.isdn.cs.tu-berlin.de>
······@lavielle.com (Rainer Joswig) writes:

> In article <·········@news.chiark.greenend.org.uk>, Mark Carroll <·····@chiark.greenend.org.uk> wrote:
> 
> > In article <·······················@pbg3.lavielle.com>,
> > Rainer Joswig <······@lavielle.com> wrote:
> > (snip)
> > >Hmm, in MCL I can set
> > >
> > >(setf *print-abbreviate-quote* nil)
> > >
> > >and it prints as you expect.
> > >I don't know how you get around this
> > >in other Lisps. Anyone?
> > 
> > Setting *print-pretty* to nil seems to do the trick. (-:
> 
> Portably?

I would think so.  First of all the standard does state the exact
algorithm to use when printing conses, if *print-pretty* is nil in
22.1.3.5:

Wherever possible, list notation is preferred over dot notation. Therefore the
following algorithm is used to print a cons x:

1. A left-parenthesis is printed.
     
2. The car of x is printed.
     
3. If the cdr of x is itself a cons, it is made to be the current cons (i.e.,
x becomes that cons), a space is printed, and step 2 is re-entered.
     
4. If the cdr of x is not null, a space, a dot, a space, and the cdr of x are
printed.
     
5. A right-parenthesis is printed.

This seems to preclude the special-casing of lists with a car of QUOTE 
or FUNCTION.

And furthermore, special-casing of QUOTE and FUNCTION forms in
printing seems most appropriate in printing of code, for which
pretty-printing is the intended mechanism.

At least that seems to be the theory.  CMU CL and ACL definitely seem
to behave this way, whereas the version of CLISP I have (which doesn't 
have the ansi flag), ignores the setting of *print-pretty*.  Maybe
newer versions and/or the ansi flag change that.  I haven't had the
time to check the other implementations I have access to, though.

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
From: Tim Bradshaw
Subject: Re: 'function cons question
Date: 
Message-ID: <nkjso62w7dm.fsf@tfeb.org>
Mark Carroll <·····@chiark.greenend.org.uk> writes:

> I'm stuck with using some Allegro application image for something. It
> has the interesting behaviour:
> 

> Anyone any ideas how to prepend a list with the symbol FUNCTION?
> 

You just did.  The printer is printing the usual shorthand for
(FUNCTION x) which is #'x.  You'll find a similar thing for (QUOTE x)
-> 'x.

--tim
From: Pierre R. Mai
Subject: Re: 'function cons question
Date: 
Message-ID: <87so62b6ec.fsf@orion.dent.isdn.cs.tu-berlin.de>
Mark Carroll <·····@chiark.greenend.org.uk> writes:

> I'm stuck with using some Allegro application image for something. It
> has the interesting behaviour:

Depending on settings for the (default r-e-p loop) printer, most CL
implementations will behave the same.  This has nothing to do with
cons, but is only related to printing.  This, along with many other
confusions brought about by the failure to differentiate between
internal data and external presentation, is probably an FAQ...

> lisp: (cons 'some-symbol '("a string"))
> (SOME-SYMBOL "a string")
> lisp: (cons 'function '("a string"))
> #'"a string"
> lisp: 
> 
> Anyone any ideas how to prepend a list with the symbol FUNCTION?

You have already done that:

> lisp: (cons 'function '("a string"))
> #'"a string"

Now type (car *) and you will get:

FUNCTION

The result of (cons 'function '("a string")) really is 
(function ("a string")) as you might have expected.  Just as with
quote, though, there exists a nice read-syntax to abbreviate having to 
write the long form, and ACL's print decides to use that to print
lists with one element and a car of function.  But this is solely a
presentation matter:

(equal '(function "a string") (cons 'function '("a string")))

still holds and returns true.  Similarly you will get

lisp: (cons 'function '(1 2))
(FUNCTION 1 2)

There probably exist tuning options to ACL's printer that will let you 
enable/disable the printing of (function X) as #'X, look at the
documentation provided with ACL.

Generally you will do better in the future, if you keep in mind that
in Lisp (as well as computer science and information/communication
theory) there is a strong distinction between (internal) data and the
external representations used to denote it, and that the mappings
between internal and external representations are often not 1:1.
Another example:

(1 . (2 . nil)) and (1 2) are different external representation for
the same internal data structure (which is often called a list of two
numbers 1 and 2, but really is just a degenerate case of a binary tree
structure).  If the result of (list 1 2) would be printed as 

(1 . (2 . nil))

it would still be a list of 1 and 2, as requested by your invocation
of list.

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]