public abstract class CasaLispOperator extends SpecialOperator implements Comparable<CasaLispOperator>
Title: CASA Agent Infrastructure
Description:
Use this class to implement ABCL (lisp) operators that work in the context of an agent. Use it by subclassing this class, overriding theexecute(TransientAgent,ParamsMap,AgentUI, Environment)
method.
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 |
CasaLispOperator.Entry
|
Modifier and Type | Field and Description |
---|---|
private static ConcurrentSkipListSet<CasaLispOperator> |
all |
private boolean |
allowOtherKeys |
private Class<?> |
classRestriction
the class (or subclass thereof) that this operator is restricted to
|
private Class<?> |
definingClass
the defining Class for this operator (set in the contructor, used in help)
|
private String |
doc |
private static CasaLispOperator |
ECHO
Lisp operator: (echo)
This is here for debugging and experimentation purposes only. |
private static CasaLispOperator |
HELP
Lisp operator: (?)
Displays the list of all casa lisp operators with the first sentence of documentation. |
private TreeMap<String,CasaLispOperator.Entry> |
keyed |
private String |
name
the name of the operator
|
private ArrayList<CasaLispOperator.Entry> |
ordered |
private int |
required |
private LinkedList<String> |
synonyms |
lambdaName
Constructor and Description |
---|
CasaLispOperator(String name,
String arglist,
Class<? extends TransientAgent> agentClass,
Class<?> definingClass,
String... synonyms)
Constructs a new casaLispOperator.
|
Modifier and Type | Method and Description |
---|---|
private Object |
checkType(CasaLispOperator.Entry entry,
LispObject lispObj,
Environment env,
ParamsMap params) |
int |
compareTo(CasaLispOperator o) |
private LispObject |
evalDefault(LispObject o,
Environment env)
Interpret the argument o in the context of the lisp environment.
|
LispObject |
execute(LispObject args,
Environment env)
Interprets the lisp command according specification in the constructor and
calls
execute(TransientAgent, ParamsMap, AgentUI, Environment) for the actual
implementation of the command with the appropriate parameters filled
out. |
abstract Status |
execute(TransientAgent agent,
ParamsMap params,
AgentUI ui,
Environment env)
Subclasses need to override the method to implement the actual operator.
|
String |
getDoc() |
String |
getDocShort() |
String |
getName() |
<Ty> Ty |
getSymbolValue(String name,
Environment env)
Look for a symbol named name in the lisp environment and return it's value.
|
static Iterator<CasaLispOperator> |
iteratorFor(Class<? extends TransientAgent> agentClass)
Will return an iterator over all the casaLispOperators that were defined
for (by?) agents of the parameter class.
|
private static LispAccessible.Argument |
makeArgument(String argName,
String help)
Constructs an argument pair (describes parameter for
CasaLispOperator ). |
static CasaLispOperator |
makeCasaLispOperator(Class<? extends TransientAgent> agentClass,
Method aMethod)
Creates a new
CasaLispOperator given a method and a transient agent. |
void |
makeSynonym(String name)
Create a synonym for this lisp command in the lisp environment.
|
private String |
pad(String s,
int n)
Return s padded out with space characters so that the length of return
string is n or more.
|
static String |
primName2ClassName(String className) |
private String |
printName(LispObject obj) |
private CasaLispOperator.Entry |
readVar(LispObject def)
Read a variable from an atom that's either a simple "var" form
or the "(var default)" form (the "(var default svar)" form is not
yet implemented).
|
String |
toString(ParamsMap params) |
execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, getCallCount, getHotCount, incrementCallCount, incrementHotCount, setCallCount, setHotCount, writeToString
getLambdaList, getLambdaName, getParts, setLambdaList, setLambdaName
ABS, add, add, aref_long, aref, AREF, AREF, aset, aset, aset, ash, ash, atom, ATOM, caddr, cadr, car, cddr, cdr, CHAR, characterp, CHARACTERP, chars, classOf, COMPLEXP, constantp, CONSTANTP, copyToArray, decr, DENOMINATOR, dispatch, divideBy, doubleValue, elt, endp, ENDP, EQ, eql, eql, eql, EQL, equal, equal, EQUAL, equalp, equalp, evenp, EVENP, floatp, FLOATP, floatValue, getBooleanValue, getDescription, getDocumentation, getFixnumSlotValue, getInstance, getPropertyList, getSlotValue_0, getSlotValue_1, getSlotValue_2, getSlotValue_3, getSlotValue, getSlotValueAsBoolean, getStringChars, getStringValue, getSymbolFunction, getSymbolFunctionOrDie, getSymbolSetfFunction, getSymbolSetfFunctionOrDie, getSymbolValue, incr, integerp, INTEGERP, intValue, IS_E, IS_GE, IS_GT, IS_LE, IS_LT, IS_NE, isEqualTo, isEqualTo, isGreaterThan, isGreaterThan, isGreaterThanOrEqualTo, isGreaterThanOrEqualTo, isLessThan, isLessThan, isLessThanOrEqualTo, isLessThanOrEqualTo, isNotEqualTo, isNotEqualTo, isSpecialOperator, isSpecialVariable, javaInstance, javaInstance, LDB, length, LENGTH, listp, LISTP, lockableInstance, LOGAND, LOGAND, LOGIOR, LOGIOR, LOGNOT, LOGXOR, LOGXOR, longValue, minusp, MINUSP, MOD, MOD, multiplyBy, multiplyBy, negate, noFillPointer, NOT, nreverse, NTH, NTH, nthcdr, numberp, NUMBERP, NUMERATOR, oddp, ODDP, plusp, PLUSP, psxhash, psxhash, push, rationalp, RATIONALP, realp, REALP, resolve, reverse, RPLACA, RPLACD, SCHAR, setCar, setCdr, setDocumentation, setPropertyList, setSlotValue_0, setSlotValue_1, setSlotValue_2, setSlotValue_3, setSlotValue, setSlotValue, SIMPLE_STRING_P, SLOT_VALUE, STRING, stringp, STRINGP, subtract, subtract, SVREF, svset, sxhash, SYMBOLP, truncate, typeOf, typep, unreadableString, unreadableString, unreadableString, unreadableString, VECTOR_PUSH_EXTEND, VECTOR_PUSH_EXTEND, vectorp, VECTORP, vectorPushExtend, zerop, ZEROP
private String name
private Class<?> classRestriction
private Class<?> definingClass
private ArrayList<CasaLispOperator.Entry> ordered
private boolean allowOtherKeys
private int required
private TreeMap<String,CasaLispOperator.Entry> keyed
private String doc
private static ConcurrentSkipListSet<CasaLispOperator> all
private LinkedList<String> synonyms
private static final CasaLispOperator HELP
private static final CasaLispOperator ECHO
CasaLispOperator#execute(TransientAgent, Map, AgentUI, Environment)
method.
Lambda List: first &optional (second 2 second_default) third &rest rest &key named bool &allow-other-keys FIRST first param SECOND [optional def=2.0] second optional param with default THIRD [optional] third optional param REST [def=&rest] the rest of the line, including keys :NAMED1 named1 doc :BOOL bool doc
public CasaLispOperator(String name, String arglist, Class<? extends TransientAgent> agentClass, Class<?> definingClass, String... synonyms)
execute(TransientAgent, ParamsMap, AgentUI, Environment)
method. The format of arglist is:
{doc-string}* {var [type-spec] [doc-string]}* [&OPTIONAL {{var | ( var [initform [svar]])} [type-spec] [doc-string] }*] [&REST var [doc-string]] [&KEY {var | ({var | (keyword var)} [initform [svar]]) [type-spec] [doc-string]}* [&ALLOW-OTHER-KEYS]] [&AUX {var | (var [initform])}*])where doc-string := "!{characters}*" (a quoted string that begins with an exclamation mark) and type-spec := "@type-name" (a quoted string specifying a lisp type with an "@" prepended).
name
- The name of the operatorarglist
- The arglist in doc-string augmented Lambda-list format.agentClass
- The class of the agent for which this function is to be registered against (may be null).definingClass
- The class that defines this operator (for help functions)synonyms
- a ... list of synonyms to be used for this same casaLispOperator.ControlTransfer
- for any number of reasonspublic int compareTo(CasaLispOperator o)
compareTo
in interface Comparable<CasaLispOperator>
private String printName(LispObject obj)
public void makeSynonym(String name)
name
- The name of the new synonym for this lisp command.public static CasaLispOperator makeCasaLispOperator(Class<? extends TransientAgent> agentClass, Method aMethod)
CasaLispOperator
given a method and a transient agent.
The method must be annotated with a LispAccessible
otherwise it will
be ignored.agentClass
- the class that has the methodaMethod
- the method to create a CasaLispOperator
forCasaLispOperator
private static final LispAccessible.Argument makeArgument(String argName, String help)
CasaLispOperator
).argName
- the argument namehelp
- a description of the argumentLispAccessible
pair representationprivate String pad(String s, int n)
s
- The string to pad out.n
- The minimum length of the return stringprivate CasaLispOperator.Entry readVar(LispObject def) throws ControlTransfer
def
- The definition in Cons form.ControlTransfer
public LispObject execute(LispObject args, Environment env) throws ControlTransfer
execute(TransientAgent, ParamsMap, AgentUI, Environment)
for the actual
implementation of the command with the appropriate parameters filled
out.execute
in class LispObject
ControlTransfer
LispObject.execute(org.armedbear.lisp.LispObject, org.armedbear.lisp.Environment)
public <Ty> Ty getSymbolValue(String name, Environment env) throws ClassCastException
Ty
- The type to return (this will be checked)name
- The name of the lisp Symbolenv
- The lisp environment, which will be used to check for symbol valuesClassCastException
- if the type doesn't conform to type Typrivate Object checkType(CasaLispOperator.Entry entry, LispObject lispObj, Environment env, ParamsMap params) throws ControlTransfer
entry
- The entryjavaObj
- The java object version of the valuelispObj
- The lisp object version of the valueenv
- The lisp environmentparams
- The params mapControlTransfer
- if there's a parameter mismatch with the entryprivate LispObject evalDefault(LispObject o, Environment env) throws ControlTransfer
o
- The value to interpret.env
- The lisp Environment in which to interpret the value.ControlTransfer
public abstract Status execute(TransientAgent agent, ParamsMap params, AgentUI ui, Environment env) throws ControlTransfer
Return | Indicates... |
---|---|
Status(0) | the method was successful, but there is no return value (possibly it printed to ui ); will return NIL |
Status(-ve,"message") | the method failed and the return will be a lisp error object with "message" as its message |
Status(+ve,"warning") | the method was successful with warnings, but there is no return value (possibly it printed to ui ); will return NIL and print the warning to ui |
StatusObject(0,LispObject) | the method was successful, and will directly return object |
Status(+ve,"warning") | the method was successful with warnings, and will return object and print the warning to ui |
agent
- The calling agentparams
- The dictionary of all the actual parameter name/value pairs that appear in function call.ui
- The AgentUI object that this method may use for input and outputenv
- The Lisp environment to use for this execution -- you can use this to instantiate symbols, etc in the context of Lisp execution.ControlTransfer
public String getName()
public String getDoc()
public String getDocShort()
public String toString(ParamsMap params)
params
- the parameter object.public static Iterator<CasaLispOperator> iteratorFor(Class<? extends TransientAgent> agentClass)
agentClass
- A class object that will be used to filter the next()'s of the iterator. Only operators compatible with the class are returned.