Package net.hydromatic.morel.eval
Class Closure
- java.lang.Object
-
- net.hydromatic.morel.eval.Closure
-
- All Implemented Interfaces:
java.lang.Comparable<Closure>,Applicable
public class Closure extends java.lang.Object implements java.lang.Comparable<Closure>, Applicable
Value that is sufficient for a function to bind its argument and evaluate its body.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectapply(EvalEnv env, java.lang.Object argValue)(package private) EvalEnvbind(java.lang.Object argValue)Binds an argument value to create a new environment for a closure.(package private) java.lang.ObjectbindEval(java.lang.Object argValue)Similar tobind(java.lang.Object), but also evaluates.private booleanbindRecurse(Ast.Pat pat, EvalEnv[] envRef, java.lang.Object argValue)intcompareTo(Closure o)(package private) EvalEnvevalBind(EvalEnv env)Similar tobind(java.lang.Object), but evaluates an expression first.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.hydromatic.morel.eval.Applicable
asCode
-
-
-
-
Field Detail
-
evalEnv
private final EvalEnv evalEnv
Environment for evaluation. Contains the variables "captured" from the environment when the closure was created.
-
patCodes
private final com.google.common.collect.ImmutableList<Pair<Ast.Pat,Code>> patCodes
A list of (pattern, code) pairs. During bind, the value being bound is matched against each pattern. When a match is found, the code for that pattern is used to evaluate.For example, when applying
fn x => case x of 0 => "yes" | _ => "no"to the value1, the first pattern (0fails) but the second pattern pattern (_) succeeds, and therefore we evaluate the second code"no".
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(Closure o)
- Specified by:
compareToin interfacejava.lang.Comparable<Closure>
-
bind
EvalEnv bind(java.lang.Object argValue)
Binds an argument value to create a new environment for a closure.When calling a simple function such as
(fn x => x + 1) 2, the binder sets just contains one variable,x, and the new environment containsx = 1. If the function's parameter is a match, more variables might be bound. For example, when you invoke(fn (x, y) => x + y) (3, 4), the binder setsxto 3 andyto 4.
-
evalBind
EvalEnv evalBind(EvalEnv env)
Similar tobind(java.lang.Object), but evaluates an expression first.
-
bindEval
java.lang.Object bindEval(java.lang.Object argValue)
Similar tobind(java.lang.Object), but also evaluates.
-
apply
public java.lang.Object apply(EvalEnv env, java.lang.Object argValue)
- Specified by:
applyin interfaceApplicable
-
-