public abstract class BoundSymbols extends Object
Title: CASA Agent Infrastructure
Description:
Supports a set of symbols and values who's value can be later looked up from both Java and Lisp
(defined in an Environment object). To support Conversation
s, where symbols are
declared with expressions and later resolved at instantiation time by evaluating
those expressions, the method bindExp(String, LispObject)
can be used to record the
expression at declaration time, and the method evaluate(TransientAgent, Environment, Map)
can be used at evaluate the expressions at instantiation time.
In addition, this class supports a hierarchy (not a lattice) of symbols through
getParent()
, where BOTH a variable NAMES may be mapped to different names in the
parent, and VALUES may be mapped to different values in the parent. Thus,
getPrimitiveRaw(String)
may return the parent's
(or parent's parent's...) BoundSymbols.Value
structure if it is referenced through
BoundSymbols.Value.reference
. In addition, get(String)
and bind(String, Object)
use translate VALUES through the local BoundSymbols.Value.valueMap
when returning or
putting values.
The following diagram shows a slightly-simplified diagram of how a 2-level nested get(String)
operation
work for a referenced (bindTo(String, String, String)
) symbol that also has a valueMap
(bindValue(String, Object, Object)
), showing two BoundSymbols.Value
objects (one "local", and the other one in the parent:
The diagram shows how get(String)
looks up the the symbol, and uses the reference to map to the value in
the parent's Value, then uses this parent's value and to translate the result back to a local value using the local
valueMap. The operation is recursive.
Copyright: Copyright 2003-2014, Knowledge Science Group, University of Calgary. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The Knowledge Science Group makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
Company: Knowledge Science Group, University of Calgary
Modifier and Type | Class and Description |
---|---|
(package private) class |
BoundSymbols.Value
Data associated with each named symbol
|
Modifier and Type | Field and Description |
---|---|
private TreeMap<String,BoundSymbols.Value> |
vars
The symbol/
BoundSymbols.Value dictionary |
Constructor and Description |
---|
BoundSymbols()
Default constructor
|
BoundSymbols(BoundSymbols copy)
Copy constructor
|
Modifier and Type | Method and Description |
---|---|
void |
bind(String sym,
Object val)
Bind a symbol to a value.
|
void |
bindExp(String sym,
LispObject exp)
Bind a symbol to an expression.
|
void |
bindTo(String localSym,
String globalSym)
bind localSym to the parent's symbol globalSym
|
void |
bindTo(String localSym,
String childName,
String childSym)
bind the childSym in the childName child to the local symbol, localSym
|
void |
bindValue(String sym,
Object fromVal,
Object toVal)
For the SYMBOL sym, bind the VALUE fromVal to be treated as being equivalent to the VALUE toVal.
|
void |
evaluate(TransientAgent agent,
Environment env,
Map<String,LispObject> newBindings)
Used to resolve all symbols created with the
bindExp(String, LispObject) method by evaluating the expression given and
assigning the result to the value of the symbol. |
Environment |
extendEnv(Environment env)
Return a new environment based on env with the symbols in vars bound.
|
Object |
get(String sym)
Return the value associated with symbol sym.
|
protected abstract BoundSymbols |
getChild(String name) |
protected abstract Collection<String> |
getChildren() |
Map<String,LispObject> |
getMap()
Return symbol map compatible with
Lisp.abclEval(TransientAgent, Environment, Map, String, casa.ui.AgentUI) 's Map parameter that represents
the bindings for this BoundSymbols object. |
protected abstract BoundSymbols |
getParent() |
private BoundSymbols.Value |
getPrimitiveRaw(String sym) |
private Object |
getSymbolTrans(String sym) |
String |
reportSymbol(String sym) |
String |
toStringBound(int indent) |
String |
toStringBoundTo(int indent) |
String |
toStringBoundValue(int indent,
String forSym) |
String |
toStringBoundValues(int indent,
String sym,
String myName)
Usually the PARENT makes use of the returned text!!!
|
private String |
toStringValue(Object o) |
private TreeMap<String,BoundSymbols.Value> vars
BoundSymbols.Value
dictionarypublic BoundSymbols()
public BoundSymbols(BoundSymbols copy)
copy
- Creates a deep copy of this Objectpublic void bindExp(String sym, LispObject exp)
get(String)
will throw an exception if
the evaluate(TransientAgent, Environment, Map)
method is not called beforehand.
Note also that the expression will be ignored if this is a reference.sym
- the symbol to bindexp
- the expression to be bound to the symbolpublic void bind(String sym, Object val)
bindExp(String, LispObject)
or bindTo(String, String)
is called subsequently, this
value will be ignored.
Note that the expression will be ignored if this is a reference.sym
- the symbol to bindval
- the value of to be bound to the symbolpublic void evaluate(TransientAgent agent, Environment env, Map<String,LispObject> newBindings)
bindExp(String, LispObject)
method by evaluating the expression given and
assigning the result to the value of the symbol.agent
- The agent in who's context to evaluate the expression in.env
- The environment.newBindings
- A map of bindings that will be applied to env.public void bindTo(String localSym, String globalSym)
localSym
- globalSym
- public void bindTo(String localSym, String childName, String childSym) throws IllegalOperationException
localSym
- childName
- childSym
- IllegalOperationException
- if childName cannot be foundpublic Object get(String sym) throws IllegalOperationException
BoundSymbols.Value.reference
for this sym is null, then the local value is returned (
If there is valueMap for this symbol, a reverse lookup is performed, and
the first match is returned. If there is an expression for this symbol
it must have already been evaluated by evaluate(TransientAgent, Environment, Map)
or an Exception is thrown.sym
- the symbol for which to return the value forIllegalOperationException
- if this symbol was created with bindExp(String, LispObject)
and evaluate(TransientAgent, Environment, Map)
has not been executed since.public String reportSymbol(String sym)
sym
- The symbol to report onprivate BoundSymbols.Value getPrimitiveRaw(String sym)
sym
- A Symbol to return the BoundSymbols.Value
for.BoundSymbols.Value
object, whether an ancestor's or local, or null if there is no associated value.public Environment extendEnv(Environment env) throws IllegalOperationException
env
- IllegalOperationException
- if any of the symbols have not yet been evaluated.public Map<String,LispObject> getMap() throws IllegalOperationException
Lisp.abclEval(TransientAgent, Environment, Map, String, casa.ui.AgentUI)
's Map parameter that represents
the bindings for this BoundSymbols object.IllegalOperationException
- if any of the symbols have not yet been evaluated.protected abstract BoundSymbols getParent()
protected abstract BoundSymbols getChild(String name)
name
- The name of the child to return.protected abstract Collection<String> getChildren()
public String toStringBound(int indent)
indent
- the number of character spaces to pad at the beginning of each line.public String toStringBoundValues(int indent, String sym, String myName)
indent
- the number of character spaces to pad at the beginning of each line.public String toStringBoundTo(int indent)
indent
- the number of character spaces to pad at the beginning of each line.public String toStringBoundValue(int indent, String forSym)
indent
- the number of character spaces to pad at the beginning of each line.public void bindValue(String sym, Object fromVal, Object toVal) throws IllegalOperationException
sym
- The name of a symbol already registered through bind(String, Object)
or bindExp(String, LispObject)
or bindTo(String, String, String)
.fromVal
- The value to bind.toVal
- The target value.IllegalOperationException
- if the symbol is not found.