slogo.jelan.expressions
Class Variable
java.lang.Object
slogo.jelan.GrammarElement
slogo.jelan.expressions.Expression
slogo.jelan.expressions.Variable
- All Implemented Interfaces:
- java.lang.Comparable<Variable>
public class Variable
- extends Expression
- implements java.lang.Comparable<Variable>
A variable stores a value and can be used in an expression. Clients can
create many objects representing a variable, say "X", but each of these maps
to the same object so that there is a common value for any occurrence of a
named-variable
- See Also:
VariableFactory
Constructor Summary |
Variable(java.lang.String name)
|
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Variable
public Variable(java.lang.String name)
evaluate
public java.lang.Double evaluate(Context c)
- Description copied from class:
GrammarElement
- Evaluate this language construct in some context. The evaluation may have
side-effects, e.g., moving a turtle.
- Overrides:
evaluate
in class Expression
- Parameters:
c
- context in which the evaluation takes place
- Returns:
- the result of evaluating the construct
value
public double value(Context c)
- Specified by:
value
in class Expression
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in class java.lang.Object
compareTo
public int compareTo(Variable v)
- Compares variables alphabetically by name
- Specified by:
compareTo
in interface java.lang.Comparable<Variable>
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object