diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-12-23 15:53:00 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-12-23 15:53:00 +0000 |
commit | 7d603560e3a43ba8e787a38312319ff0d6139b54 (patch) | |
tree | 7e3b5a8bf100136c2fc341d03ac451af82a9ffe1 /src | |
parent | db7f3d1cea1b380ddad39cfb2e5b62efe78047ea (diff) |
~x not in syntax-quote yields (clojure.core/unquote x)
clojure.core/unquote has no root binding
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/core.clj | 2 | ||||
-rw-r--r-- | src/jvm/clojure/lang/LispReader.java | 23 |
2 files changed, 12 insertions, 13 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index be452aa4..4cb7fd66 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -8,6 +8,8 @@ (ns clojure.core) +(def unquote) + (def #^{:arglists '([& items]) :doc "Creates a new list containing the items."} diff --git a/src/jvm/clojure/lang/LispReader.java b/src/jvm/clojure/lang/LispReader.java index db4424cf..0e94c009 100644 --- a/src/jvm/clojure/lang/LispReader.java +++ b/src/jvm/clojure/lang/LispReader.java @@ -25,7 +25,7 @@ public class LispReader{ static final Symbol QUOTE = Symbol.create("quote");
static final Symbol THE_VAR = Symbol.create("var");
//static Symbol SYNTAX_QUOTE = Symbol.create(null, "syntax-quote");
-//static Symbol UNQUOTE = Symbol.create(null, "unquote");
+static Symbol UNQUOTE = Symbol.create("clojure.core", "unquote");
//static Symbol UNQUOTE_SPLICING = Symbol.create(null, "unquote-splicing");
static Symbol CONCAT = Symbol.create("clojure.core", "concat");
static Symbol LIST = Symbol.create("clojure.core", "list");
@@ -683,8 +683,8 @@ public static class SyntaxQuoteReader extends AFn{ sym = Compiler.resolveSymbol(sym);
ret = RT.list(Compiler.QUOTE, sym);
}
- else if(form instanceof Unquote)
- return ((Unquote) form).o;
+ else if(isUnquote(form))
+ return RT.second(form);
else if(form instanceof UnquoteSplicing)
throw new IllegalStateException("splice not in list");
else if(form instanceof IPersistentCollection)
@@ -733,8 +733,8 @@ public static class SyntaxQuoteReader extends AFn{ for(; seq != null; seq = seq.rest())
{
Object item = seq.first();
- if(item instanceof Unquote)
- ret = ret.cons(RT.list(LIST, ((Unquote) item).o));
+ if(isUnquote(item))
+ ret = ret.cons(RT.list(LIST, RT.second(item)));
else if(item instanceof UnquoteSplicing)
ret = ret.cons(((UnquoteSplicing) item).o);
else
@@ -756,13 +756,6 @@ public static class SyntaxQuoteReader extends AFn{ }
-static class Unquote{
- final Object o;
-
- public Unquote(Object o){
- this.o = o;
- }
-}
static class UnquoteSplicing{
final Object o;
@@ -772,6 +765,10 @@ static class UnquoteSplicing{ }
}
+static boolean isUnquote(Object form){
+ return form instanceof ISeq && RT.first(form).equals(UNQUOTE);
+}
+
static class UnquoteReader extends AFn{
public Object invoke(Object reader, Object comma) throws Exception{
PushbackReader r = (PushbackReader) reader;
@@ -787,7 +784,7 @@ static class UnquoteReader extends AFn{ {
unread(r, ch);
Object o = read(r, true, null, true);
- return new Unquote(o);
+ return RT.list(UNQUOTE, o);
}
}
|