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