Class Constant

java.lang.Object
  extended by Constant
All Implemented Interfaces:
Expression

public class Constant
extends java.lang.Object
implements Expression

A Constant is an expression with a directly specified value.


Constructor Summary
Constant(java.lang.Object obj)
          Creates a Constant for a Value representing the specified Object.
Constant(Value value)
          Creates a Constant with the specified Value.
 
Method Summary
 Value eval(Environment env)
          Evaluate this expression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Constant

public Constant(java.lang.Object obj)
Creates a Constant for a Value representing the specified Object. This is a convenience constructor; for example new Constant(17) is equivalent to, but more convenient than, new Constant(new BoxedValue(17)).

Parameters:
obj - the Object to be packaged into a BoxedValue

Constant

public Constant(Value value)
Creates a Constant with the specified Value.

Parameters:
value - the Value the expression should evaluate to
Method Detail

eval

public Value eval(Environment env)
Description copied from interface: Expression
Evaluate this expression. When an Expression is evaluated, this must happen in some particular environment. For example, evaluating the variable x in one environment might produce a totally different value than evaluating it in another environment.

Specified by:
eval in interface Expression
Parameters:
env - the environment in which the expression should be evaluated
Returns:
the value produced by the expression