Is there a difference between ,. and ,@?
Thanx!
,. vs ,@
-
- Posts: 78
- Joined: Mon Dec 01, 2014 12:29 pm
- Contact:
Re: ,. vs ,@
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:
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.
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)))