Package kiss.lang

Examples of kiss.lang.Environment


public class EnvironmentTests {

  @Test public void testDef() {
    Expression x=Def.create(Symbol.intern("foo"),Constant.create(1));
    Environment e=Environment.EMPTY;
   
    Environment e2=x.compute(e);
    assertEquals(1,e2.get(Symbol.intern("foo")));
    assertEquals(1,e2.getResult());
  }
View Full Code Here


    assertEquals(1,e2.get(Symbol.intern("foo")));
    assertEquals(1,e2.getResult());
  }
 
  @Test public void testValidity() {
    Environment e=Environment.EMPTY;
    e.validate();
   
    e=Def.create(Symbol.intern("foo"),Constant.create(1)).compute(e);
    e.validate();
   
    e=Def.create(Symbol.intern("bar"),Lookup.create("foo")).compute(e);
    e.validate();
   
    e=Def.create(Symbol.intern("bar"),Lookup.create("baz")).compute(e);
    e.validate();
  }
View Full Code Here

  @Override
  public Environment compute(Environment d, IPersistentMap bindings) {
    if (compiled!=null) return d.withResult(compiled);
   
    // TODO is this sensible? capture the dynamic environment at exact point of lambda creation?
    Environment e=d;
    for (ISeq s= bindings.seq(); s!=null; s=s.next()) {
      Entry<?, ?> me=(Entry<?, ?>)s.first();
      e=e.assoc(me.getKey(),me.getValue());
    }
   
    KFn fn=LambdaFn.create(e,body,syms);
    return d.withResult(fn);
  }
View Full Code Here

    if (args.length!=arity) throwArity(args.length);
    IPersistentMap bindings=PersistentHashMap.EMPTY;
    for (int i=0; i<arity; i++) {
      bindings=bindings.assoc(params[i], args[i]);
    }
    Environment e=body.compute(env, bindings);
    while (true) {
      Object ro=e.getResult();
      if (ro instanceof ReturnResult) return ((ReturnResult) ro).value;
      if (!(ro instanceof RecurResult)) break;
      RecurResult re=(RecurResult) ro;
      for (int i=0; i<arity; i++) {
        bindings=bindings.assoc(params[i], re.values[i]);
      }
      e=body.compute(e,bindings);
    }
    return e.getResult();
  }
View Full Code Here

    return type;
  }
 
  @Override
  public Environment compute(Environment d, IPersistentMap bindings) {
    Environment ev= body.compute(d, bindings);
    if (ev.isExiting()) return ev;
    Object result=ev.getResult();
    if (type.checkInstance(result)) {
      throw new KissException("Can't cast value of class "+KissUtils.typeName(result)+" to "+type);
     
    }
    return ev;
View Full Code Here

TOP

Related Classes of kiss.lang.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.