Permalink
Browse files

impose once semantics on fabricated closures for e.g. loops

  • Loading branch information...
richhickey committed Jan 28, 2013
1 parent a5f786a commit 9b80a552fdabeabdd93951a625b55ae49c2f8d83
Showing with 7 additions and 6 deletions.
  1. +1 −1 clojure.iml
  2. +6 −5 src/jvm/clojure/lang/Compiler.java
View
@@ -18,7 +18,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.jsr166-mirror:jsr166y:1.7.0" level="project" />
- <orderEntry type="library" scope="TEST" name="Maven: org.clojure:test.generative:0.1.9" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.clojure:test.generative:0.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.clojure:tools.namespace:0.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.clojure:java.classpath:0.1.1" level="project" />
</component>
@@ -44,6 +44,7 @@
static final Symbol LETFN = Symbol.intern("letfn*");
static final Symbol DO = Symbol.intern("do");
static final Symbol FN = Symbol.intern("fn*");
+static final Symbol FNONCE = (Symbol) Symbol.intern("fn*").withMeta(RT.map(Keyword.intern(null, "once"), RT.T));
static final Symbol QUOTE = Symbol.intern("quote");
static final Symbol THE_VAR = Symbol.intern("var");
static final Symbol DOT = Symbol.intern(".");
@@ -2123,7 +2124,7 @@ public Expr parse(C context, Object frm) {
ISeq form = (ISeq) frm;
// if(context == C.EVAL || context == C.EXPRESSION)
if(context != C.RETURN)
- return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form)));
+ return analyze(context, RT.list(RT.list(FNONCE, PersistentVector.EMPTY, form)));
//(try try-expr* catch-expr* finally-expr?)
//catch-expr: (catch class sym expr*)
@@ -2299,7 +2300,7 @@ public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
static class Parser implements IParser{
public Expr parse(C context, Object form) {
if(context == C.EVAL)
- return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form)));
+ return analyze(context, RT.list(RT.list(FNONCE, PersistentVector.EMPTY, form)));
return new ThrowExpr(analyze(C.EXPRESSION, RT.second(form)));
}
}
@@ -5805,7 +5806,7 @@ public Expr parse(C context, Object frm) {
ISeq body = RT.next(RT.next(form));
if(context == C.EVAL)
- return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form)));
+ return analyze(context, RT.list(RT.list(FNONCE, PersistentVector.EMPTY, form)));
IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(),
NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref());
@@ -5934,7 +5935,7 @@ public Expr parse(C context, Object frm) {
if(context == C.EVAL
|| (context == C.EXPRESSION && isLoop))
- return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form)));
+ return analyze(context, RT.list(RT.list(FNONCE, PersistentVector.EMPTY, form)));
ObjMethod method = (ObjMethod) METHOD.deref();
IPersistentMap backupMethodLocals = method.locals;
@@ -8366,7 +8367,7 @@ private static void emitExpr(ObjExpr objx, GeneratorAdapter gen, Expr expr, bool
public Expr parse(C context, Object frm) {
ISeq form = (ISeq) frm;
if(context == C.EVAL)
- return analyze(context, RT.list(RT.list(FN, PersistentVector.EMPTY, form)));
+ return analyze(context, RT.list(RT.list(FNONCE, PersistentVector.EMPTY, form)));
PersistentVector args = PersistentVector.create(form.next());
Object exprForm = args.nth(0);

0 comments on commit 9b80a55

Please sign in to comment.