Skip to content

Commit 7d60356

Browse files
committed
~x not in syntax-quote yields (clojure.core/unquote x)
clojure.core/unquote has no root binding
1 parent db7f3d1 commit 7d60356

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/clj/clojure/core.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
(ns clojure.core)
1010

11+
(def unquote)
12+
1113
(def
1214
#^{:arglists '([& items])
1315
:doc "Creates a new list containing the items."}

src/jvm/clojure/lang/LispReader.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class LispReader{
2525
static final Symbol QUOTE = Symbol.create("quote");
2626
static final Symbol THE_VAR = Symbol.create("var");
2727
//static Symbol SYNTAX_QUOTE = Symbol.create(null, "syntax-quote");
28-
//static Symbol UNQUOTE = Symbol.create(null, "unquote");
28+
static Symbol UNQUOTE = Symbol.create("clojure.core", "unquote");
2929
//static Symbol UNQUOTE_SPLICING = Symbol.create(null, "unquote-splicing");
3030
static Symbol CONCAT = Symbol.create("clojure.core", "concat");
3131
static Symbol LIST = Symbol.create("clojure.core", "list");
@@ -683,8 +683,8 @@ else if(form instanceof Symbol)
683683
sym = Compiler.resolveSymbol(sym);
684684
ret = RT.list(Compiler.QUOTE, sym);
685685
}
686-
else if(form instanceof Unquote)
687-
return ((Unquote) form).o;
686+
else if(isUnquote(form))
687+
return RT.second(form);
688688
else if(form instanceof UnquoteSplicing)
689689
throw new IllegalStateException("splice not in list");
690690
else if(form instanceof IPersistentCollection)
@@ -733,8 +733,8 @@ private static ISeq sqExpandList(ISeq seq) throws Exception{
733733
for(; seq != null; seq = seq.rest())
734734
{
735735
Object item = seq.first();
736-
if(item instanceof Unquote)
737-
ret = ret.cons(RT.list(LIST, ((Unquote) item).o));
736+
if(isUnquote(item))
737+
ret = ret.cons(RT.list(LIST, RT.second(item)));
738738
else if(item instanceof UnquoteSplicing)
739739
ret = ret.cons(((UnquoteSplicing) item).o);
740740
else
@@ -756,13 +756,6 @@ private static IPersistentVector flattenMap(Object form){
756756

757757
}
758758

759-
static class Unquote{
760-
final Object o;
761-
762-
public Unquote(Object o){
763-
this.o = o;
764-
}
765-
}
766759

767760
static class UnquoteSplicing{
768761
final Object o;
@@ -772,6 +765,10 @@ public UnquoteSplicing(Object o){
772765
}
773766
}
774767

768+
static boolean isUnquote(Object form){
769+
return form instanceof ISeq && RT.first(form).equals(UNQUOTE);
770+
}
771+
775772
static class UnquoteReader extends AFn{
776773
public Object invoke(Object reader, Object comma) throws Exception{
777774
PushbackReader r = (PushbackReader) reader;
@@ -787,7 +784,7 @@ public Object invoke(Object reader, Object comma) throws Exception{
787784
{
788785
unread(r, ch);
789786
Object o = read(r, true, null, true);
790-
return new Unquote(o);
787+
return RT.list(UNQUOTE, o);
791788
}
792789
}
793790

0 commit comments

Comments
 (0)