Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain Clojure's unquote-splice in simple terms?

Tags:

clojure

I am banging my head against the wall trying to understand some Clojure macros which use unquote-splice, and I can't seem to find out any clear expanation of whay they are needed. Can anyone explain it to me in dummy terms?

like image 514
yazz.com Avatar asked Dec 31 '10 16:12

yazz.com


1 Answers

I'm no expert on Clojure, but since it's basically a Lisp, things should be like that unquote-splice is unquote which merges the list to the position where it's used. Difference looks like this:

`(1 2 ~(list 3 4))   =>  (1 2 (3 4))
`(1 2 ~@(list 3 4))  =>  (1 2 3 4)

`  == syntax-quote
~  == unquote
~@ == unquote-splice
like image 55
Mirek Kratochvil Avatar answered Oct 24 '22 17:10

Mirek Kratochvil