,. vs ,@

Discussion of Common Lisp
Post Reply
filfil
Posts: 12
Joined: Mon Aug 06, 2012 3:21 pm

,. vs ,@

Post by filfil » Sun Dec 14, 2014 9:07 am

Is there a difference between ,. and ,@?

Thanx!

David Mullen
Posts: 78
Joined: Mon Dec 01, 2014 12:29 pm
Contact:

Re: ,. vs ,@

Post by David Mullen » Sun Dec 14, 2014 12:01 pm

Common Lisp has non-destructive and destructive versions of some functions—REVERSE and NREVERSE, for example. So the backquote syntax has ",." (destructive) and ",@" (non-destructive). Some simple examples of how the backquote syntax expands to regular call forms:

Code: Select all

? '`(foo ,@bar)
(LIST* 'FOO BAR)
? '`(foo ,.bar)
(LIST* 'FOO BAR)
? '`(foo ,@bar ,baz)
(LIST* 'FOO (APPEND BAR (LIST BAZ)))
? '`(foo ,.bar ,baz)
(LIST* 'FOO (NCONC BAR (LIST BAZ)))
In the first two forms, ",." versus ",@" makes no difference because the BAR is in the tail position. But in the latter two forms, ",@" uses APPEND and ",." uses NCONC. The destructive version would be okay if you knew the list being spliced was safe to modify—i.e. without trampling on somebody else's data.

filfil
Posts: 12
Joined: Mon Aug 06, 2012 3:21 pm

Re: ,. vs ,@

Post by filfil » Sun Dec 14, 2014 4:45 pm

Thank you!

Post Reply