macro / backquote notation

Discussion of Common Lisp

macro / backquote notation

Postby 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
filfil
 
Posts: 10
Joined: Mon Aug 06, 2012 3:21 pm

Re: macro / backquote notation

Postby 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).
User avatar
Goheeca
 
Posts: 214
Joined: Thu May 10, 2012 12:54 pm

Re: macro / backquote notation

Postby filfil » Sun Jul 07, 2013 6:39 am

Thank you very much!
filfil
 
Posts: 10
Joined: Mon Aug 06, 2012 3:21 pm

Re: macro / backquote notation

Postby 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/
findinglisp
 
Posts: 440
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX

Re: macro / backquote notation

Postby filfil » Mon Jul 08, 2013 11:20 pm

It's a macroexpander.Thank you for the warning!
filfil
 
Posts: 10
Joined: Mon Aug 06, 2012 3:21 pm


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 4 guests

cron