org.rubato.scheme
Class Env

java.lang.Object
  extended by org.rubato.scheme.SExpr
      extended by org.rubato.scheme.Env

public final class Env
extends SExpr

The class representing Scheme environments. Environments are linked as stacks. Searching for a symbol starts at top environment and follows links until the ground environment is reached.

Author:
Gérard Milmeister

Field Summary
 
Fields inherited from class org.rubato.scheme.SExpr
NULL, VOID
 
Constructor Summary
Env()
          Creates an empty ground environment.
Env(Env link)
          Creates an empty environment on top of the environment link.
 
Method Summary
 void addPrimitive(Primitive p)
          Binds primitive function p to its name in this environment.
 java.lang.String display()
          Returns a string representation of this SExpr.
 boolean eq_p(SExpr sexpr)
          Returns true iff this is equal to sexpr in the eq? sense.
 boolean equal_p(SExpr sexpr)
          Returns true iff this is equal to sexpr in the equal? sense.
 boolean equals(java.lang.Object obj)
          Returns true iff this is equal to obj.
 boolean eqv_p(SExpr sexpr)
          Returns true iff this is equal to sexpr in the eqv? sense.
 boolean extendEnv(SExpr vars, SExpr vals)
          Extends this environment with bindings for each symbol in vars to its correspondings value in vals.
 SExpr get(Symbol sym)
          Returns the expression bound to the symbol sym.
 java.util.Set<java.util.Map.Entry<Symbol,SExpr>> getBindings()
          Returns all bindings in this environment.
static Env makeGlobalEnvironment()
          Creates a ground environment containing bindings for all standard and all Rubato-specific primitives.
static Env makeStandardEnvironment()
          Creates a ground environment containing bindings for all standard primitives.
 Env pop()
          Returns the environment that this environment is linked to.
 Env push()
          Returns a new empty environment pushed on top of this.
 void put(java.lang.String sym, SExpr expr)
          Binds the symbol with string representation sym to the expression sexpr in this environment.
 void put(Symbol sym, SExpr sexpr)
          Binds the symbol sym to the expression sexpr in this environment.
 void resetGlobal()
          Resets this environment to contain only standard and Rubato-specific primitives.
 void resetStandard()
          Resets this environment to contain only standard primitives.
 boolean set(Symbol sym, SExpr expr)
          Binds the symbol with string representation sym to the expression sexpr in this environment.
 java.lang.String toString()
          Returns a string representation of this SExpr.
 
Methods inherited from class org.rubato.scheme.SExpr
car, cdr, cons, getCar, getCdr, getLength, isBoolean, isChar, isClosure, isComplex, isCons, isDenotator, isForm, isInteger, isList, isNull, isNumber, isPair, isPrimitive, isRational, isReal, isString, isSymbol, isVector, isVoid, nth, setCar, setCdr
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Env

public Env()
Creates an empty ground environment.


Env

public Env(Env link)
Creates an empty environment on top of the environment link.

Method Detail

push

public Env push()
Returns a new empty environment pushed on top of this.


pop

public Env pop()
Returns the environment that this environment is linked to.


put

public void put(Symbol sym,
                SExpr sexpr)
Binds the symbol sym to the expression sexpr in this environment.


put

public void put(java.lang.String sym,
                SExpr expr)
Binds the symbol with string representation sym to the expression sexpr in this environment.


get

public SExpr get(Symbol sym)
Returns the expression bound to the symbol sym. If there is no binding in this environment, follows the link. If there is no binding at all, returns null.


set

public boolean set(Symbol sym,
                   SExpr expr)
Binds the symbol with string representation sym to the expression sexpr in this environment. The binding only succeeds, if the symbol has already been bound. In this case true is returned, otherwise nothing happens, and false is returned.


getBindings

public java.util.Set<java.util.Map.Entry<Symbol,SExpr>> getBindings()
Returns all bindings in this environment.


addPrimitive

public void addPrimitive(Primitive p)
Binds primitive function p to its name in this environment.


extendEnv

public boolean extendEnv(SExpr vars,
                         SExpr vals)
Extends this environment with bindings for each symbol in vars to its correspondings value in vals.


eq_p

public boolean eq_p(SExpr sexpr)
Description copied from class: SExpr
Returns true iff this is equal to sexpr in the eq? sense.

Specified by:
eq_p in class SExpr

eqv_p

public boolean eqv_p(SExpr sexpr)
Description copied from class: SExpr
Returns true iff this is equal to sexpr in the eqv? sense.

Specified by:
eqv_p in class SExpr

equal_p

public boolean equal_p(SExpr sexpr)
Description copied from class: SExpr
Returns true iff this is equal to sexpr in the equal? sense.

Specified by:
equal_p in class SExpr

equals

public boolean equals(java.lang.Object obj)
Description copied from class: SExpr
Returns true iff this is equal to obj. Normally this returns the same result as SExpr.equal_p(org.rubato.scheme.SExpr).

Specified by:
equals in class SExpr

toString

public java.lang.String toString()
Description copied from class: SExpr
Returns a string representation of this SExpr.

Specified by:
toString in class SExpr

display

public java.lang.String display()
Description copied from class: SExpr
Returns a string representation of this SExpr. This is the representation intended to show the result of an evaluation, and should be a valid Scheme expression if possible.

Specified by:
display in class SExpr

makeGlobalEnvironment

public static Env makeGlobalEnvironment()
Creates a ground environment containing bindings for all standard and all Rubato-specific primitives.


makeStandardEnvironment

public static Env makeStandardEnvironment()
Creates a ground environment containing bindings for all standard primitives.


resetGlobal

public void resetGlobal()
Resets this environment to contain only standard and Rubato-specific primitives.


resetStandard

public void resetStandard()
Resets this environment to contain only standard primitives.