Changeset 11547


Ignore:
Timestamp:
01/05/09 15:26:01 (13 years ago)
Author:
vvoutilainen
Message:

For let, variable values must be bound after the let-forms.
This patch postpones the binds until all let-forms have been
evaluated, aka just before the body is evaluated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/SpecialOperators.java

    r11488 r11547  
    3535
    3636import java.util.ArrayList;
    37 
     37import java.util.LinkedList;
    3838public final class SpecialOperators extends Lisp
    3939{
     
    110110    };
    111111
     112  private static final void bindArg(LispObject specials, Symbol symbol,
     113             LispObject value, Environment ext)
     114    throws ConditionThrowable
     115    {
     116      final LispThread thread = LispThread.currentThread();
     117      if (specials != NIL && memq(symbol, specials))
     118  {
     119    thread.bindSpecial(symbol, value);
     120    ext.declareSpecial(symbol);
     121  }
     122      else if (symbol.isSpecialVariable())
     123  {
     124    thread.bindSpecial(symbol, value);
     125  }
     126      else
     127    ext.bind(symbol, value);
     128    }
     129
    112130  private static final LispObject _let(LispObject args, Environment env,
    113131                                       boolean sequential)
     
    148166          }
    149167        Environment ext = new Environment(env);
     168  LinkedList<Cons> nonSequentialVars = new LinkedList<Cons>();
    150169        while (varList != NIL)
    151170          {
     
    181200                value = NIL;
    182201              }
    183             if (specials != NIL && memq(symbol, specials))
    184               {
    185                 thread.bindSpecial(symbol, value);
    186                 ext.declareSpecial(symbol);
    187               }
    188             else if (symbol.isSpecialVariable())
    189               {
    190                 thread.bindSpecial(symbol, value);
    191               }
    192             else
    193               ext.bind(symbol, value);
     202      if (sequential)
     203    bindArg(specials, symbol, value, ext);
     204      else
     205    nonSequentialVars.add(new Cons(symbol, value));
    194206            varList = ((Cons)varList).cdr;
    195207          }
     208  if (!sequential)
     209    {
     210      for (Cons x : nonSequentialVars)
     211        {
     212    bindArg(specials, (Symbol)x.car(), x.cdr(), ext);
     213        }
     214    }
    196215        // Make sure free special declarations are visible in the body.
    197216        // "The scope of free declarations specifically does not include
Note: See TracChangeset for help on using the changeset viewer.