macro / backquote notation

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

macro / backquote notation

Post by filfil » Sun Jul 07, 2013 5:52 am

Hi,

I've found an expression like this

Code: Select all

`(and ,.(first (nreverse ris)))
that is seems, evaluating, the same of

Code: Select all

`(and ,@(first (nreverse ris)))
I've never seen or read about [,.]: is that anything different with [,@]?

Thanks

filfil

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: macro / backquote notation

Post by Goheeca » Sun Jul 07, 2013 6:30 am

Yes, comma-dot operates destructively with the form which is unquoted by that. Look at this SBCL session:

Code: Select all

* (defvar *a* (list 'a 'b 'c))

*A*
* `(1 2 3 ,@*a* 4 5 6)

(1 2 3 A B C 4 5 6)
* *a*

(A B C)
* `(1 2 3 ,.*a* 4 5 6)

(1 2 3 A B C 4 5 6)
* *a*

(A B C 4 5 6)
*
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

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

Re: macro / backquote notation

Post by filfil » Sun Jul 07, 2013 6:39 am

Thank you very much!

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: macro / backquote notation

Post by findinglisp » Mon Jul 08, 2013 7:54 pm

filfil, was the usage you found in performance critical code, or just a macro expander? If the latter, it seems like a false economy. Better to use ,@ and avoid the possibility of bugs caused by destructively modifying the following form, IMO. Generally, if your macro expander runs incrementally slower, you simply won't notice or care.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

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

Re: macro / backquote notation

Post by filfil » Mon Jul 08, 2013 11:20 pm

It's a macroexpander.Thank you for the warning!

Post Reply