Skip to content

Commit

Permalink
impose once semantics on fabricated closures for e.g. loops
Browse files Browse the repository at this point in the history
  • Loading branch information
richhickey committed Jan 28, 2013
1 parent a5f786a commit 9b80a55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clojure.iml
Expand Up @@ -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>
Expand Down
11 changes: 6 additions & 5 deletions src/jvm/clojure/lang/Compiler.java
Expand Up @@ -44,6 +44,7 @@ public class Compiler implements Opcodes{
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(".");
Expand Down Expand Up @@ -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*)
Expand Down Expand Up @@ -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)));
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -8366,7 +8367,7 @@ static class Parser implements IParser{
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);
Expand Down

0 comments on commit 9b80a55

Please sign in to comment.