From: Chez17
Subject: Noob Question: Can somebody explain to me what @ does in front of a 	loop
Date: 
Message-ID: <4eb5cbdd-e633-415a-8bfa-5115e8326980@i7g2000prf.googlegroups.com>
Hello all,

I am a complete beginner in the world of lisp. I am using CMUCL as
instructed by the book I am reading, Practical Common Lisp. It has
brief description of what the @ symbol does to an expression(is form
the right word here?) but I don't fully understand it. I tried looking
in the Lisp Cookbook but didn't even know what section to begin in. A
normal google search for 'Lisp @' doesn't help either. Can somebody
give me a break down of what is going on. Here is some code from the
book:

(defmacro check (&body forms)
  `(combine-results
     ,@(loop for f in forms collect `(report-result ,f ',f))))

I understand why the comma is there and what relation it has to the `
character. I just don't understand exactly what the @ symbol does.
Thanks in advance for your time and help.

Dave

From: ······@corporate-world.lisp.de
Subject: Re: Noob Question: Can somebody explain to me what @ does in front of 	a loop
Date: 
Message-ID: <c49cdf24-5978-4217-8bfe-e6cf8a4afa76@e25g2000prg.googlegroups.com>
On Feb 10, 9:50 pm, Chez17 <······@gmail.com> wrote:
> Hello all,
>
> I am a complete beginner in the world of lisp. I am using CMUCL as
> instructed by the book I am reading, Practical Common Lisp. It has
> brief description of what the @ symbol does to an expression(is form
> the right word here?) but I don't fully understand it. I tried looking
> in the Lisp Cookbook but didn't even know what section to begin in. A
> normal google search for 'Lisp @' doesn't help either. Can somebody
> give me a break down of what is going on. Here is some code from the
> book:
>
> (defmacro check (&body forms)
>   `(combine-results
>      ,@(loop for f in forms collect `(report-result ,f ',f))))
>
> I understand why the comma is there and what relation it has to the `
> character. I just don't understand exactly what the @ symbol does.
> Thanks in advance for your time and help.
>
> Dave

Say (foo) returns a list (1 2 3)

`(a ,(foo) b) puts the result of evaluating (foo) into the list   ->
(a (1 2 3) b)

`(a ,@(foo) b) splices the result of evaluating (foo) into the list   -
>  (a 1 2 3 b)
From: Chez17
Subject: Re: Noob Question: Can somebody explain to me what @ does in front of 	a loop
Date: 
Message-ID: <04f70d76-3267-4a95-af6d-afeb72cad617@p69g2000hsa.googlegroups.com>
Wow, a simple explanation like that makes it a lot clearer. Thanks so
much.
From: Paul Donnelly
Subject: Re: Noob Question: Can somebody explain to me what @ does in front of a  loop
Date: 
Message-ID: <87wspczewn.fsf@plap.localdomain>
Chez17 <······@gmail.com> writes:

> (defmacro check (&body forms)
>   `(combine-results
>      ,@(loop for f in forms collect `(report-result ,f ',f))))
>
> I understand why the comma is there and what relation it has to the `
> character. I just don't understand exactly what the @ symbol does.
> Thanks in advance for your time and help.

The @ sign is only meaningful in this context. Otherwise it's just a
regular symbol that can be used like any other letter. Inside a
backquoted form, you can either type ,foo to substitute the contents of
the variable foo into the form, or you can type ,@foo to "splice in" the
contents of the variable foo, as long as it's a list. E.g.

(let ((foo '(a b c)))
  `(d ,foo e))             => (d (a b c) e)

(let ((foo '(a b c)))
  `(d ,@foo e))            => (d a b c e)
From: Thomas F. Burdick
Subject: Re: Noob Question: Can somebody explain to me what @ does in front of 	a loop
Date: 
Message-ID: <34f875fa-6553-456d-8c0f-26e31c46560f@i12g2000prf.googlegroups.com>
On Feb 10, 10:21 pm, Paul Donnelly <·············@sbcglobal.net>
wrote:
> Chez17 <······@gmail.com> writes:
> > (defmacro check (&body forms)
> >   `(combine-results
> >      ,@(loop for f in forms collect `(report-result ,f ',f))))
>
> > I understand why the comma is there and what relation it has to the `
> > character. I just don't understand exactly what the @ symbol does.
> > Thanks in advance for your time and help.
>
> The @ sign is only meaningful in this context. Otherwise it's just a
> regular symbol that can be used like any other letter. Inside a
> backquoted form, you can either type ,foo to substitute the contents of
> the variable foo into the form, or you can type ,@foo to "splice in" the
> contents of the variable foo, as long as it's a list. E.g.
>
> (let ((foo '(a b c)))
>   `(d ,foo e))             => (d (a b c) e)
>
> (let ((foo '(a b c)))
>   `(d ,@foo e))            => (d a b c e)

Incidentally, although you can name your variables @foo, it's probably
not such a good idea...

  (let ((foo '(1 2 3))
        (@foo '(a b c))
    (values (list 'letters @foo)
            `(letters ,@foo)))

  => (letters (a b c))
  => (letters 1 2 3)
From: Kent M Pitman
Subject: Re: Noob Question: Can somebody explain to me what @ does in front of  a loop
Date: 
Message-ID: <ubq6nzh5a.fsf@nhplace.com>
"Thomas F. Burdick" <········@gmail.com> writes:

> Incidentally, although you can name your variables @foo, it's probably
> not such a good idea...
> 
>   (let ((foo '(1 2 3))
>         (@foo '(a b c))
>     (values (list 'letters @foo)
>             `(letters ,@foo)))
> 
>   => (letters (a b c))
>   => (letters 1 2 3)

Yeah, most Lisp implementations have to have their pretty printers taught
to write
 , @foo
to comma-ify a variable named @foo.
From: Thomas F. Burdick
Subject: Re: Noob Question: Can somebody explain to me what @ does in front of 	a loop
Date: 
Message-ID: <6d662b3d-b19a-43ac-b431-9e364e510f40@n20g2000hsh.googlegroups.com>
On Feb 11, 3:45 pm, Kent M Pitman <······@nhplace.com> wrote:
> "Thomas F. Burdick" <········@gmail.com> writes:
>
> > Incidentally, although you can name your variables @foo, it's probably
> > not such a good idea...
>
> >   (let ((foo '(1 2 3))
> >         (@foo '(a b c))
> >     (values (list 'letters @foo)
> >             `(letters ,@foo)))
>
> >   => (letters (a b c))
> >   => (letters 1 2 3)
>
> Yeah, most Lisp implementations have to have their pretty printers taught
> to write
>  , @foo
> to comma-ify a variable named @foo.

Wow, you're right, I tried

  (quote `(, @x))

on the two Lisps I use (Allegro and SBCL), and SBCL printed the form
correctly and Allegro got it wrong.