From: ······@gmail.com
Subject: difficulties to understand the atom concept
Date: 
Message-ID: <1164742772.635829.65150@45g2000cws.googlegroups.com>
Hi,

I'm trying to write an interpreter for a lisp-like language in cl
(while learning cl).
In my eval function, I check if the form I receive is an atom. If not,
I process it
in a eval-list function.

The problem is that, whenever I type 'g for instance, the 'not' branch
of the if is taken.
So 'g is not an atom... but what is it ?
Here's a few try in clisp to understand the thing but it doesn't help
me.
Can someone explain it ?

[1]> (atom (read))
g
T
[2]> (atom (read))
'g
NIL    <--- so what is it ?
[3]> (atom 'g)
T        <- I guess atom receive an unevaluated g...
[4]> (atom '1)
T
[5]> (atom 1)
T
[6]> (quit)

Also :

[1]> (read)
'g
'G
[2]> (read)
g
G
[3]> (quit)


I guess there something intern to lisp that can't be shown otherwise
that with a quote but I can't formalize it.

Oh, btw, what would be the corresponding construct in lisp for an
erlang atom ?
Any quoted lisp atom ?

Thanks,
Thu

From: Aaron Brown
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <1164743582.619895.28060@14g2000cws.googlegroups.com>
······@gmail.com wrote:

> The problem is that, whenever I type 'g for instance, the
> 'not' branch of the if is taken.  So 'g is not an atom...
> but what is it ?

> [1]> (atom (read))
> g
> T
> [2]> (atom (read))
> 'g
> NIL    <--- so what is it ?

'g is shorthand for (quote g), which is a list.  The purpose
of the QUOTE operator is to protect its argument from
evaluation, but neither READ nor ATOM evaluate what READ
reads, so you don't need to quote it (and if you do, you'll
see a list, as above).

-- 
Aaron
http://www.amazon.com/gp/product/0470069171/
From: Frank Buss
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <1sadm33puj7ob$.7dmsg7wz3c4b.dlg@40tude.net>
······@gmail.com wrote:

> [2]> (atom (read))
> 'g
> NIL    <--- so what is it ?

It is a list:

> (equal (quote g) 'g)
T

-- 
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: ······@gmail.com
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <1164743749.577219.170970@80g2000cwy.googlegroups.com>
On Nov 28, 8:48 pm, Frank Buss <····@frank-buss.de> wrote:
> ······@gmail.com wrote:
> > [2]> (atom (read))
> > 'g
> > NIL    <--- so what is it ?It is a list:
>
> > (equal (quote g) 'g)T
>

A list which is rendered as 'g, right ?
But I though that quote was a macro (since it doesn't evaluate its
argument) so (quote g) must be reducible to something else...
or lisp can't exist without macro ? I mean, if someone write its own
dialect of lisp, must he add macro in its dialect to represent quoted
things ?
(i.e. if I'm correct, to represent code).

Anyway, thanks for your answer,
thu
From: Bill Atkins
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <m2slg3s5f5.fsf@weedle-24.dynamic.rpi.edu>
······@gmail.com writes:

> A list which is rendered as 'g, right ?
> But I though that quote was a macro (since it doesn't evaluate its
> argument) so (quote g) must be reducible to something else...

QUOTE is a special form.  There are about twenty of these in Lisp, and
for the most part they can't be reduced into other Lisp code.  You
should explore this more if you want to write an interpreter.
From: ······@gmail.com
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <1164744715.154786.300870@h54g2000cwb.googlegroups.com>
On Nov 28, 9:05 pm, Bill Atkins <······@rpi.edu> wrote:
> ······@gmail.com writes:
> > A list which is rendered as 'g, right ?
> > But I though that quote was a macro (since it doesn't evaluate its
> > argument) so (quote g) must be reducible to something else...QUOTE is a special form.  There are about twenty of these in Lisp, and
> for the most part they can't be reduced into other Lisp code.  You
> should explore this more if you want to write an interpreter.

Thank you a lot everybody, I've my answer :)
I forgot about special forms.
Thu
From: Pascal Bourguignon
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <87bqmr9uq9.fsf@thalassa.informatimago.com>
······@gmail.com writes:

> On Nov 28, 8:48 pm, Frank Buss <····@frank-buss.de> wrote:
>> ······@gmail.com wrote:
>> > [2]> (atom (read))
>> > 'g
>> > NIL    <--- so what is it ?It is a list:
>>
>> > (equal (quote g) 'g)T
>>
>
> A list which is rendered as 'g, right ?

Yes, some implementations have strange printers, which print 'x for
(cl:quote x) and #'x for (cl:function x).


But you can easily write your own printer function:

(defun print-list (list)
    (loop :for item :in list
          :do (format t "~&item: ~S~%" item))
    list)

C/USER2[59]> (print-list ''x)
item: QUOTE
item: X
'X
C/USER2[60]> (print-list (read))
'x
item: QUOTE
item: X
'X
C/USER2[61]> (print-list (read))
(quote x)
item: QUOTE
item: X
'X


> But I though that quote was a macro

No.  QUOTE is a symbol.

C/USER2[62]> (type-of 'quote)
SYMBOL
C/USER2[63]> (type-of (read))
quote
SYMBOL


> (since it doesn't evaluate its argument)  so (quote g) must be
> reducible to something else...

Ah, but this  is something else.  First you are considering a _form_,
that is a symbolic expression (s-exp) that represents specificaly a
lisp program.  A form can be either an atom, or a list, whose car can
be either a symbol bound to a function or a macro, or naming a special
operator, or a lambda expression.

(QUOTE G) is a form, a list whose CAR names a special operator.  The
special operators are evaluated specially by the lisp interpreter or
compiler.


'G is (CL:QUOTE G) is a list containing two symbols, the symbol QUOTE and
the symbol G.

WHEN you EVALUATE the form (CL:QUOTE G), you get the symbol G as result.
The symbol G is an atom, but the form (CL:QUOTE G) is not.  What goes
in between, is the EVALUATION.


> or lisp can't exist without macro ? 

Lisp can exist without macros.  But it's not funny without :-)


> I mean, if someone write its own dialect of lisp, must he add macro
> in its dialect to represent quoted things ?

No. QUOTE is a special operator, a primitive that must be implemented
in the interpreter.  Macros can't help here.


-- 
__Pascal_Bourguignon__               _  Software patents are endangering
()  ASCII ribbon against html email (o_ the computer industry all around
/\  1962:DO20I=1.100                //\ the world http://lpf.ai.mit.edu/
    2001:my($f)=`fortune`;          V_/   http://petition.eurolinux.org/
From: ······@gmail.com
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <1164815017.986154.173410@l12g2000cwl.googlegroups.com>
On Nov 28, 9:33 pm, Pascal Bourguignon <····@informatimago.com> wrote:
> ······@gmail.com writes:
> > On Nov 28, 8:48 pm, Frank Buss <····@frank-buss.de> wrote:
> >> ······@gmail.com wrote:
> >> > [2]> (atom (read))
> >> > 'g
> >> > NIL    <--- so what is it ?It is a list:
>
> >> > (equal (quote g) 'g)T
>
> > A list which is rendered as 'g, right ?Yes, some implementations have strange printers, which print 'x for
> (cl:quote x) and #'x for (cl:function x).
>
> But you can easily write your own printer function:
>
> (defun print-list (list)
>     (loop :for item :in list
>           :do (format t "~&item: ~S~%" item))
>     list)
>
> C/USER2[59]> (print-list ''x)
> item: QUOTE
> item: X
> 'X
> C/USER2[60]> (print-list (read))
> 'x
> item: QUOTE
> item: X
> 'X
> C/USER2[61]> (print-list (read))
> (quote x)
> item: QUOTE
> item: X
> 'X
>
> > But I though that quote was a macroNo.  QUOTE is a symbol.
>
> C/USER2[62]> (type-of 'quote)
> SYMBOL
> C/USER2[63]> (type-of (read))
> quote
> SYMBOL
>
> > (since it doesn't evaluate its argument)  so (quote g) must be
> > reducible to something else...Ah, but this  is something else.  First you are considering a _form_,
> that is a symbolic expression (s-exp) that represents specificaly a
> lisp program.  A form can be either an atom, or a list, whose car can
> be either a symbol bound to a function or a macro, or naming a special
> operator, or a lambda expression.
>
> (QUOTE G) is a form, a list whose CAR names a special operator.  The
> special operators are evaluated specially by the lisp interpreter or
> compiler.
>
> 'G is (CL:QUOTE G) is a list containing two symbols, the symbol QUOTE and
> the symbol G.
>
> WHEN you EVALUATE the form (CL:QUOTE G), you get the symbol G as result.
> The symbol G is an atom, but the form (CL:QUOTE G) is not.  What goes
> in between, is the EVALUATION.
>
> > or lisp can't exist without macro ?Lisp can exist without macros.  But it's not funny without :-)
>
> > I mean, if someone write its own dialect of lisp, must he add macro
> > in its dialect to represent quoted things ?No. QUOTE is a special operator, a primitive that must be implemented
> in the interpreter.  Macros can't help here.
>
> --
> __Pascal_Bourguignon__               _  Software patents are endangering
> ()  ASCII ribbon against html email (o_ the computer industry all around
> /\  1962:DO20I=1.100                //\ the worldhttp://lpf.ai.mit.edu/
>     2001:my($f)=`fortune`;          V_/  http://petition.eurolinux.org/

Merci beaucoup Pascal, mais je pense que j'ai compris : vraiment
j'avais just oublie les special forms.
Desole si je n'etais pas clair avec la distinction
representation/evaluation (quote qui est simplment un symbol) mais ce
n'etait pas la ou mon probleme se situait.

Thu
From: Bill Atkins
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <m2slg2xfg7.fsf@weedle-24.dynamic.rpi.edu>
······@gmail.com writes:

> Merci beaucoup Pascal, mais je pense que j'ai compris : vraiment
> j'avais just oublie les special forms.
> Desole si je n'etais pas clair avec la distinction
> representation/evaluation (quote qui est simplment un symbol) mais ce
> n'etait pas la ou mon probleme se situait.
> Thu

Thanks.  Thanks for making me feel left out.
From: Raffael Cavallaro
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <2006113001470316807-raffaelcavallaro@pasdespamsilvousplaitmaccom>
On 2006-11-29 13:42:16 -0500, Bill Atkins <······@rpi.edu> said:

> ······@gmail.com writes:
> 
>> Merci beaucoup Pascal, mais je pense que j'ai compris : vraiment
>> j'avais just oublie les special forms.
>> Desole si je n'etais pas clair avec la distinction
>> representation/evaluation (quote qui est simplment un symbol) mais ce
>> n'etait pas la ou mon probleme se situait.
>> Thu
> 
> Thanks.  Thanks for making me feel left out.

Thank you very much Pascal, but I think I understand; I really just 
forgot about special forms.
Sorry if I was unclear with the distinction beteween representation and 
evaluation (quote being simply a symbol) but that was not where my 
problem lay.


Free Translation Services Provided by Ed's Polyglot Grill - "A Damned 
Fine Burger in *Any* Language!"
From: ······@gmail.com
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <1164877020.741248.28200@80g2000cwy.googlegroups.com>
On Nov 30, 7:47 am, Raffael Cavallaro
<················@pas-d'espam-s'il-vous-plait-mac.com> wrote:
> On 2006-11-29 13:42:16 -0500, Bill Atkins <······@rpi.edu> said:
>
> > ······@gmail.com writes:
>
> >> Merci beaucoup Pascal, mais je pense que j'ai compris : vraiment
> >> j'avais just oublie les special forms.
> >> Desole si je n'etais pas clair avec la distinction
> >> representation/evaluation (quote qui est simplment un symbol) mais ce
> >> n'etait pas la ou mon probleme se situait.
> >> Thu
>
> > Thanks.  Thanks for making me feel left out.Thank you very much Pascal, but I think I understand; I really just
> forgot about special forms.
> Sorry if I was unclear with the distinction beteween representation and
> evaluation (quote being simply a symbol) but that was not where my
> problem lay.
>
> Free Translation Services Provided by Ed's Polyglot Grill - "A Damned
> Fine Burger in *Any* Language!"

Sorry, I won't do that again; even if what I say is of little interest
:)
Bye, Thu
From: Raffael Cavallaro
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <2006120201233443658-raffaelcavallaro@pasdespamsilvousplaitmaccom>
On 2006-11-30 03:57:00 -0500, ······@gmail.com said:

> Sorry, I won't do that again; even if what I say is of little interest

I don't mean to discourage posts in non-english languages - it's just 
polite to provide a brief summary translation for others, that's all.
From: Sidney Markowitz
Subject: Re: difficulties to understand the atom concept
Date: 
Message-ID: <456c936d$0$82563$742ec2ed@news.sonic.net>
······@gmail.com wrote, On 29/11/06 8:39 AM:
> So 'g is not an atom... but what is it ?
> Here's a few try in clisp to understand the thing but it doesn't help
> me.
> Can someone explain it ?

'g evaluates to an atom, but it is not itself an atom, just like the
list (+ 1 1) evaluates to 2 but as a list is not 2.

The ' character is a reader macro that is expanded by the reader so that

 'g

is read as

 (quote g)

Part of your problem is that by default the printer outputs a "pretty"
form of expressions that coverts (quote g) back into the compact form 'g.

If you want to see what is going on, try this

(let ((*print-pretty* nil)) (print (read)))

If you type 'g at that you will see that it is actually (quote g).

-- 
    Sidney Markowitz
    http://www.sidney.com