codesimian
Class DefaultCS

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
All Implemented Interfaces:
CodeSimian, java.io.Serializable
Direct Known Subclasses:
Above, AbsoluteValue, Add, AddParam, AddressShape, ArcSin, Ask, BayesNet, BayesNode, BayesNode.VerifyCountP, BayesNodeDependence, BayesNodePredictError, BayesNodeUpdate, Binary, ButtonCS, ClassObject, ColorCS, CommandLine, CompareNumbers, Compile, Const, CopyParams, CopyParamToParam, Count, DeepCopy, Delay, DeleteParam, DieSpam, DieSpam.ButtonClicked, Divide, EqualP, EqualRecurse2, EvolveCode, Exec, ExecParam, FileOfShorts, Files.LoadCSFromFile, Files.SaveCSToFile, Files.TextFileWriter, FList, FTime, Function, GetJavaCompiler, GetResource, GraphSeq, HumanTypesCommand, IfElse, ImageCS, IndentCode, InternalFiles.DeleteInternalFile, InternalFiles.GetInternalFile, InternalFiles.SetInternalFile, Interpolate, InterpretText, InvokeMethod, Jars.JarTest, Jars.SaveUpdatedSelf, JavaMethod2, JavaObject, JavaType, Keyboard, Layout, ListOfStringsGUI, Log, Logic, Loop, Max, Median, Microphone, Min, Mod, MouseNumberList, MousePanel, MoveMouse, Multiply, N, NatLangType, NaturalLanguage.RemoveEverythingExceptLetters, Neg, Network, New, NothingList, Num, Object3d, ParamCount, Pow, PrimitiveArray, Ptr, RandGaussian, RandomlyCombineCode, RandomNeuron, RandRange, RecurseP, ReflectedFunctions.addP, ReflectedFunctions.addPx, ReflectedFunctions.addPxx, ReflectedFunctions.addPxxx, ReflectedFunctions.addPxxxx, ReflectedFunctions.B, ReflectedFunctions.BForProxy, ReflectedFunctions.C, ReflectedFunctions.CForProxy, ReflectedFunctions.cost, ReflectedFunctions.countP, ReflectedFunctions.D, ReflectedFunctions.decrementMyFuel, ReflectedFunctions.deleteP, ReflectedFunctions.deletePx, ReflectedFunctions.description, ReflectedFunctions.DForProxy, ReflectedFunctions.equals, ReflectedFunctions.F, ReflectedFunctions.FForProxy, ReflectedFunctions.fuel, ReflectedFunctions.getClass, ReflectedFunctions.getExec, ReflectedFunctions.getObject, ReflectedFunctions.hashCode, ReflectedFunctions.heap, ReflectedFunctions.I, ReflectedFunctions.IForProxy, ReflectedFunctions.indexP, ReflectedFunctions.indexPName, ReflectedFunctions.insertB, ReflectedFunctions.insertC, ReflectedFunctions.insertD, ReflectedFunctions.insertF, ReflectedFunctions.insertI, ReflectedFunctions.insertJ, ReflectedFunctions.insertL, ReflectedFunctions.insertL1, ReflectedFunctions.insertLx, ReflectedFunctions.insertP, ReflectedFunctions.insertS, ReflectedFunctions.insertZ, ReflectedFunctions.J, ReflectedFunctions.javaCode, ReflectedFunctions.JForProxy, ReflectedFunctions.keyword, ReflectedFunctions.L, ReflectedFunctions.LForProxy, ReflectedFunctions.LForProxyx, ReflectedFunctions.Lx, ReflectedFunctions.maxP, ReflectedFunctions.minP, ReflectedFunctions.myFuel, ReflectedFunctions.name, ReflectedFunctions.newInstance, ReflectedFunctions.notify, ReflectedFunctions.notifyAll, ReflectedFunctions.P, ReflectedFunctions.parent, ReflectedFunctions.parsePriority, ReflectedFunctions.PB, ReflectedFunctions.PC, ReflectedFunctions.PD, ReflectedFunctions.PF, ReflectedFunctions.PI, ReflectedFunctions.PJ, ReflectedFunctions.PL, ReflectedFunctions.prevB, ReflectedFunctions.prevC, ReflectedFunctions.prevD, ReflectedFunctions.prevF, ReflectedFunctions.prevI, ReflectedFunctions.prevJ, ReflectedFunctions.prevL, ReflectedFunctions.prevS, ReflectedFunctions.prevZ, ReflectedFunctions.PS, ReflectedFunctions.PType, ReflectedFunctions.PZ, ReflectedFunctions.S, ReflectedFunctions.setB, ReflectedFunctions.setBx, ReflectedFunctions.setC, ReflectedFunctions.setCost, ReflectedFunctions.setCx, ReflectedFunctions.setD, ReflectedFunctions.setDescription, ReflectedFunctions.setDx, ReflectedFunctions.setExec, ReflectedFunctions.setF, ReflectedFunctions.setFuel, ReflectedFunctions.setFx, ReflectedFunctions.setHeap, ReflectedFunctions.setI, ReflectedFunctions.setIx, ReflectedFunctions.setJ, ReflectedFunctions.setJx, ReflectedFunctions.setL, ReflectedFunctions.setL1, ReflectedFunctions.setLx, ReflectedFunctions.setLxx, ReflectedFunctions.setMyFuel, ReflectedFunctions.setName, ReflectedFunctions.setObject, ReflectedFunctions.setP, ReflectedFunctions.setParent, ReflectedFunctions.setParsePriority, ReflectedFunctions.setPrevExec, ReflectedFunctions.setPType, ReflectedFunctions.setS, ReflectedFunctions.setSx, ReflectedFunctions.setZ, ReflectedFunctions.setZx, ReflectedFunctions.SForProxy, ReflectedFunctions.toString, ReflectedFunctions.V, ReflectedFunctions.VForProxy, ReflectedFunctions.wait, ReflectedFunctions.waitx, ReflectedFunctions.waitxx, ReflectedFunctions.Z, ReflectedFunctions.ZForProxy, ReflectJavaClass, Reverse, RoundToInt, S, ScreenPixels, Scroll, SelfPredictingPrimeHashingNumberList, SetEqual, SetParam, Sets.UnionOfSets, SimpleBayesNet, SimpleBayesNet.BayesNodeIndependentChildsDependentParent, SimpleBayesNet.Test, SimpleNeuralNode, SimpleNeuralNode.ChainSimpleNeuralNodesTogether, SimpleNeuralNode.WordStringsToNodes, Sine, SlideBar, SlowMP3, Sound, SoundQuality, SpamData, SplitPane, Squares, Stacks.Peek, Stacks.Pop, Stacks.Push, Stacks.StackSize, Strings.PrintCS, Strings.PrintNumber, Strings.PrintString, Strings.ReadChar, Strings.StringSplit, Strings.TokenizeAllCharPairs, TextAreaCS, TimerCS, ToStr, TradeCalcExec, TreeList, TreeOfCodeGUI, TreeType, Try, Valid, View2d, WeightedAverage, WholeMP3, WindowCS

public abstract class DefaultCS
extends CS
implements java.io.Serializable

CS has no variables, but DefaultCS does. DefaultCS is the main subclass of CS. Most classes extend DefaultCS. DefaultCS adds more complex behaviors than CS. CS is a "skeleton" that you can use to add new Java files to CodeSimian in the most flexible way, but for most uses, DefaultCS should be enough.

There is 1 major inconsistency between CS and DefaultCS that needs to be fixed ASAP: The EXECUTE functions (B() C() etc) all defer to D() in DefaultCS, then D defers to PROXY. But CS (this is the way it should be but it doesnt work) defers to the PROXY immediately from all EXECUTE functions. However no CS EXECUTE functions remain after DefaultCS overrides. Deferring immediately, causes infinite loops. Fix it... (Exec.java needs to be modified to have all EXECUTE functions!)

Stop implementing Serializable in DefaultCS?... and only implement it in subclasses that are sure they can be serialized? If a subclass was sure it can not be serialized then DefaultCS would force it to claim its Serializable and when it tries to be serialized, an ERROR will occur. So dont force them.
To fix this, they can override private void writeObject(ObjectOutputStream) to THROW A NotSerializableException, which fools most parts of Java to think it doesnt implement Serializable, but some programs check to see if Serializable is an interface of the class and throwing a NotSerializableException wont fix that. The program will assume it is serializable because it implements the interface.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
DefaultCS()
          CSs created with this constructor might throw NullPointerExceptions if anything is done to these CSs before Static.pushOptions(CS) is called.
 
Method Summary
 byte B()
           
 char C()
           
 int countP()
          Quantity of params.
 boolean decrementMyFuel()
          Returns true if this CS has permission to execute, and consumes 1 exec permission.
If myFuel is at least 1, decrements it and returns true.
Or if myFuel == ALWAYS_CALCULATE, returns true but does not decrement.
Else returns false.
Does not call DForProxy().
 boolean deleteP(int paramNumber)
          WARNING: if returns false, could have deleted but not moved other params down 1 index.
WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false.
 java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
abstract  double DForProxy()
          D() and DForProxy() are the 2 most important functions in CS.
 float F()
           
 CS fuel()
          need to change return type from N to CS
 CS getExec()
          Every CS must have an EXECPROXY (also called PROXY), even if its a trivial wrapper.
 java.lang.Object getObject()
          Returns the main Object that this CS wraps.
 CS heap()
          returns 'this' by default.
 int I()
           
 int indexP(CS myParam)
          Returns the param index of 'myParam' in this CS or -1 if it is not this CS's param.
 int indexPName(java.lang.String pName)
          Returns the index of the PARAM with name pName, or -1 if nothing is found.
 boolean insertB(int paramIndex, byte value)
           
 boolean insertC(int paramIndex, char value)
           
 boolean insertD(int paramIndex, double value)
          inserts a double as a param at a specific index.
 boolean insertF(int paramIndex, float value)
           
 boolean insertI(int paramIndex, int value)
           
 boolean insertJ(int paramIndex, long value)
           
 boolean insertL(int startIndex, java.lang.Object insertMe)
          Inserts an Object into MULTIPLE param indexs.
 boolean insertL(int startIndex, java.lang.Object insertMe, int indexQuantity)
          Inserts an Object into a specific subset of param indexs.
 boolean insertL1(int index, java.lang.Object setToThisValue)
          inserts an Object into 1 param index.
 boolean insertP(int index, CS insertMe)
          same as setP(int,CS) but inserts instead of overwriting.
 boolean insertS(int paramIndex, short value)
           
 boolean insertZ(int paramIndex, boolean value)
           
 long J()
          Execute this CS and cast to long.
Most subclasses should override JForProxy() instead of J(), or neither.
WARNING: by default, like the other execute functions, J() calls D() and casts to J's type.
long is the only primitive type that double has problems with.
double maps to long correctly for all values between at least -(2^51) and 2^51 - 1.
Past that, accuracy is less than integer precision.
 java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
          This will work with the basic operators like + / * - and probably a few others, but complex CSs will have to override this function to specify how to translate itself into Java code in combination with its children and descendent CSs.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 java.lang.Object LForProxy(java.lang.Class castToThisType)
          the default implementation can use many Class parameters.
 java.lang.Object LForProxy(int startIndex, java.lang.Class castToThisType, int indexQuantity)
          by default, only works if castToThisType==CS[].class or is a String
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 int myFuel()
          Returns how many times this CS may EXECUTE before it needs to trade some CS fuel for int fuel.
 java.lang.String name()
          returns the name of this CS.
 CS newInstance()
          temporarily, uses Class objects to instantiate the default constructor.
protected  CS objectToCS(java.lang.Object o)
          Tries to convert an Object to a CS, to be used by insertL1(Object,int) or setL1(Object,int) etc.
protected  CS[] objectToCSArray(java.lang.Object o)
          The default way to interpret an Object as a sequence of CSs.
protected  CS[] objectToCSArray(java.lang.Object o, int arraySize)
          Like objectToCSArray(Object) but requires the array be a certain size.
 CS P(int index)
          WARNING: if add CSs then delete them, they are still in the param[] array and can be returned in this function, despite them being out of valid range: index at least countP().
 double prevD()
          previous value of D().
 java.lang.Object prevL()
          returns the previous execute value as an Object.
 CS PType(int index)
          There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1.
 short S()
           
 boolean setB(int paramIndex, byte value)
           
 boolean setC(int paramIndex, char value)
           
protected  void setCountP(int newParamQuantity)
           
 boolean setD(double setToThisValue)
          all setX functions return setD by default.
 boolean setD(int paramIndex, double value)
          sets a param to a double value.
 boolean setExec(CS e)
           
 boolean setF(int paramIndex, float value)
           
 boolean setFuel(CS setTo)
           
 boolean setI(int paramIndex, int value)
           
 boolean setJ(int paramIndex, long value)
           
 boolean setL(int startIndex, java.lang.Object setToThisValue)
          needs to be tested
 boolean setL(int startIndex, java.lang.Object setToThisValue, int indexQuantity)
          needs to be tested
 boolean setL(java.lang.Object setToThisValue)
          setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.
 boolean setL1(int index, java.lang.Object setToThisValue)
          needs to be tested
 boolean setMyFuel(int newCalculateExec)
           
 boolean setName(java.lang.String newName)
          sets the name of this CS
 boolean setObject(java.lang.Object setTo)
          Sets the main Object that this CS wraps.
 boolean setP(int index, CS setTo)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
 void setPrevExec(double p)
          rename to setPrevD.
 boolean setS(int paramIndex, short value)
           
 boolean setZ(int paramIndex, boolean value)
           
protected  void start()
          called by the default CS constructor (which has no parameters).
 java.lang.String toString()
          problem: toString() does not return the same as L(String.class).
 void V()
           
 boolean Z()
           
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultCS

public DefaultCS()
CSs created with this constructor might throw NullPointerExceptions if anything is done to these CSs before Static.pushOptions(CS) is called. Static.callMeOnceBeforeUsingCodesimianOrCodesimianWillCrash() does that.

Method Detail

V

public void V()
Overrides:
V in class CS
See Also:
Execute this CS. Do not return anything. V = Void. Some CSs have side-effects, so void is not useless.

Z

public boolean Z()
Overrides:
Z in class CS
See Also:
execute this CS and cast to boolean. By default, all positive numbers are true, 0 & neg false. Its called Z because B is used by byte, and java.lang.java.lang.Class.name() uses Z for boolean. All the functions that execute a CS have names equal to one of java.lang.java.lang.Class.name();\

B

public byte B()
Overrides:
B in class CS
See Also:
Execute this CS and cast to byte

C

public char C()
Overrides:
C in class CS
See Also:
Execute this CS and cast to char

S

public short S()
Overrides:
S in class CS
See Also:
Execute this CS and cast to short

I

public int I()
Overrides:
I in class CS
See Also:
Execute this CS and cast to int

J

public long J()
Description copied from class: CS
Execute this CS and cast to long.
Most subclasses should override JForProxy() instead of J(), or neither.
WARNING: by default, like the other execute functions, J() calls D() and casts to J's type.
long is the only primitive type that double has problems with.
double maps to long correctly for all values between at least -(2^51) and 2^51 - 1.
Past that, accuracy is less than integer precision.

Overrides:
J in class CS
See Also:
CS.L(Class), java.lang.Double.doubleToLongBits(double)

F

public float F()
Overrides:
F in class CS
See Also:
Execute this CS and cast to float

DForProxy

public abstract double DForProxy()
Description copied from class: CS
D() and DForProxy() are the 2 most important functions in CS. They execute this CS. All other execute functions, by default, use DForProxy instead of reinventing-the-wheel for their own type.

For example, J() calls JForProxy() which calls DForProxy(). D() calls DForProxy() directly.

Execute this CS and cast to double. D() is the main EXECUTE function. D() uses DForProxy(). DForProxy() is the main action of every CS, the most important function. By default, all other primitive EXECUTE functions defer to D.
Functions that EXECUTE this CS: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V()

Specified by:
DForProxy in class CS

LForProxy

public java.lang.Object LForProxy(java.lang.Class castToThisType)
                           throws CSCastException
the default implementation can use many Class parameters. If you override but do not know what to return, return super.LForProxy(Class). All EXEC objects must override L(Class) the same way they override D(), reversed.

Specified by:
LForProxy in class CS
Throws:
CSCastException
See Also:
execProxy(), setExecProxy(CS)

LForProxy

public java.lang.Object LForProxy(int startIndex,
                                  java.lang.Class castToThisType,
                                  int indexQuantity)
by default, only works if castToThisType==CS[].class or is a String

Specified by:
LForProxy in class CS
See Also:
CS.L(int,Class,int)

name

public java.lang.String name()
Description copied from class: CS
returns the name of this CS.

After keyword() is refactored out, parent().name() will replace keyword().

Specified by:
name in class CS

setName

public boolean setName(java.lang.String newName)
Description copied from class: CS
sets the name of this CS

Overrides:
setName in class CS

setD

public boolean setD(double setToThisValue)
all setX functions return setD by default. setD returns false by default. Override in subclass. For example, class N has a public variable value, and N.value is set to setToThisValue.

Specified by:
setD in class CS

setL

public boolean setL(java.lang.Object setToThisValue)
Description copied from class: CS
setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.

Specified by:
setL in class CS

setL1

public boolean setL1(int index,
                     java.lang.Object setToThisValue)
needs to be tested

Specified by:
setL1 in interface CodeSimian
Overrides:
setL1 in class CS

setL

public boolean setL(int startIndex,
                    java.lang.Object setToThisValue)
needs to be tested

Specified by:
setL in interface CodeSimian
Specified by:
setL in class CS
See Also:
CS.setL(int,Object,int)

setL

public boolean setL(int startIndex,
                    java.lang.Object setToThisValue,
                    int indexQuantity)
needs to be tested

Specified by:
setL in interface CodeSimian
Specified by:
setL in class CS

setP

public boolean setP(int index,
                    CS setTo)
Description copied from class: CS
Every CS is a list of other CSs, between size minP() and maxP() inclusive. setP overwrites one of those CSs or adds a new one at the end, depending on the index. If index is between 0 and countP()-1, overwrites. If it equals countP(), adds at end.

Specified by:
setP in class CS

myFuel

public int myFuel()
Description copied from class: CS
Returns how many times this CS may EXECUTE before it needs to trade some CS fuel for int fuel. When it runs out, it can trade to get more fuel, or it can stop executing and return its previous value instead. Example, the previous double value is prevD().

myFuel() is for this specific CS. fuel() can be shared between CSs and has more complex behaviors. Should always be 0 or positive. If 0, this CS should not EXECUTE, but it is the PROXY's job to enforce that.

Specified by:
myFuel in class CS

setMyFuel

public boolean setMyFuel(int newCalculateExec)
Specified by:
setMyFuel in class CS
See Also:
CS.myFuel()

description

public java.lang.String description()
Description copied from class: CS
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.

Specified by:
description in class CS

insertP

public boolean insertP(int index,
                       CS insertMe)
Description copied from class: CS
same as setP(int,CS) but inserts instead of overwriting. All higher params slide up 1 index.

Specified by:
insertP in class CS

indexP

public int indexP(CS myParam)
Returns the param index of 'myParam' in this CS or -1 if it is not this CS's param. If 'myParam' is in the param list more than once, returns the highest index.

Does not search the HEAP for the specified param. Fix it...

WARNING: Uses LINEAR SEARCH. Override and make faster if your CS has more than a few params.

Overrides:
indexP in class CS

indexPName

public int indexPName(java.lang.String pName)
Returns the index of the PARAM with name pName, or -1 if nothing is found. Returns an index less than -1 if the HEAP contains it (heap() and setHeap()).

(returns int) indexPName(String) ...is the inverse of... (returns String) P(int).name().

Overrides:
indexPName in class CS
See Also:
CS.name(), CS.setName(String), CS.indexP(CS)

deleteP

public boolean deleteP(int paramNumber)
WARNING: if returns false, could have deleted but not moved other params down 1 index.
WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false.

Specified by:
deleteP in class CS

fuel

public CS fuel()
need to change return type from N to CS

Specified by:
fuel in class CS

setFuel

public boolean setFuel(CS setTo)
Specified by:
setFuel in class CS
See Also:
CS.fuel()

decrementMyFuel

public boolean decrementMyFuel()
Returns true if this CS has permission to execute, and consumes 1 exec permission.
If myFuel is at least 1, decrements it and returns true.
Or if myFuel == ALWAYS_CALCULATE, returns true but does not decrement.
Else returns false.
Does not call DForProxy(). Should change this to not check "myFuel == ALWAYS_CALCULATE" because the specific subclass of Exec controls if myFuel is used to limit execution.

Specified by:
decrementMyFuel in class CS

setExec

public boolean setExec(CS e)
Overrides:
setExec in class CS
See Also:
CS.getExec()

getExec

public CS getExec()
Description copied from class: CS
Every CS must have an EXECPROXY (also called PROXY), even if its a trivial wrapper. PROXY is a middle step between all EXECUTIONS.

A PROXY should implement all 11 EXECUTE functions: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V(). A normal CS should usually not implement any of those functions. Normal CSs should instead implement DForProxy() and LForProxy(Class) etc...

A proxy's X() function should call XForProxy(), where X is one of the 11 functions above. Any CS may call X() or XForProxy(), but BE CAREFUL!! Normally a CS only calls X() and lets proxys do the rest.

Common uses are to check and update myExec(), fuel(), or change a returned NaN to 0. To add more options, add new code to Exec.javaCode(...), compile it, and paste its output into Exec.java

Specified by:
getExec in class CS

countP

public int countP()
Description copied from class: CS
Quantity of params. Should be between minP() and maxP() inclusive when you EXECUTE this CS. Can be below minP() for a short time during compiling, but you must not EXECUTE this CS during that time.

Specified by:
countP in class CS

minP

public int minP()
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Specified by:
minP in class CS

newInstance

public CS newInstance()
temporarily, uses Class objects to instantiate the default constructor. This should be fixed to copy this CS. See oldNewInstance().

Specified by:
newInstance in class CS

PType

public CS PType(int index)
Description copied from class: CS
There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1. When a TYPE executes, it MEASURES THE TYPE OF its first param CS. It returns a positive number if it is that type, else 0 or negative. Some TYPEs use only 2 numbers, while others can return any number on a continuous scale.

Types are optional. To not use types, return the default type: Static.defaultType(). The default type returns true for any CS. Most CSs do not need types therefore they use the default type.

Specified by:
PType in class CS

P

public CS P(int index)
WARNING: if add CSs then delete them, they are still in the param[] array and can be returned in this function, despite them being out of valid range: index at least countP().

Specified by:
P in class CS
Parameters:
index - range 0 to countP()-1 inclusive
See Also:
CS.heap()

heap

public CS heap()
returns 'this' by default. Should change that to return some external CS but share it between CSs to avoid using double the memory. 9/06 HEAP should become a virtual variable, only accessed by L("heap") and setL("heap",someObject) etc. Many other functions should be removed and only accessed that way also.

Specified by:
heap in class CS

insertL1

public boolean insertL1(int index,
                        java.lang.Object setToThisValue)
Description copied from class: CS
inserts an Object into 1 param index. The easiest way to do this is put it in a CS and insert that CS with setP(int,CS)

Specified by:
insertL1 in interface CodeSimian
Specified by:
insertL1 in class CS

insertL

public boolean insertL(int startIndex,
                       java.lang.Object insertMe)
Description copied from class: CS
Inserts an Object into MULTIPLE param indexs. Part of the object goes into each index.

Same as insertL(int,Object,int) but the Object determines the quantity of indexs.

Specified by:
insertL in interface CodeSimian
Specified by:
insertL in class CS
See Also:
CS.insertL(int,Object,int)

insertL

public boolean insertL(int startIndex,
                       java.lang.Object insertMe,
                       int indexQuantity)
Description copied from class: CS
Inserts an Object into a specific subset of param indexs. Part of the object goes into each index.

same as setL(int,Object,int) but INSERTS instead of REPLACES. The values in those indexs are pushed up to higher indexs.

Specified by:
insertL in class CS

prevL

public java.lang.Object prevL()
Description copied from class: CS
returns the previous execute value as an Object.

The function prevL() does not fit well into this interface. If it had a Class parameter, it would take too much instance space and time. If it has no Class parameter, it might not match the Object you're comparing to.

The functions L(Class) Z B C S I J D and F should set the values that these PREV functions return.

Other PREV functions return every other type. There are 9 PREV functions. All 9 are about the same one variable, which can be ANY type. Any one of these functions reads or writes the value of the other 8.

Specified by:
prevL in class CS

prevD

public double prevD()
previous value of D(). This function is set by setPrevExec(double) which should be renamed to setPrevD(double)

Specified by:
prevD in class CS

setZ

public boolean setZ(int paramIndex,
                    boolean value)
Overrides:
setZ in class CS
See Also:
CS.setD(int,double)

setB

public boolean setB(int paramIndex,
                    byte value)
Overrides:
setB in class CS
See Also:
CS.setD(int,double)

setC

public boolean setC(int paramIndex,
                    char value)
Overrides:
setC in class CS
See Also:
CS.setD(int,double)

setS

public boolean setS(int paramIndex,
                    short value)
Overrides:
setS in class CS
See Also:
CS.setD(int,double)

setI

public boolean setI(int paramIndex,
                    int value)
Overrides:
setI in class CS
See Also:
CS.setD(int,double)

setJ

public boolean setJ(int paramIndex,
                    long value)
Overrides:
setJ in class CS
See Also:
CS.setD(int,double)

setF

public boolean setF(int paramIndex,
                    float value)
Overrides:
setF in class CS
See Also:
CS.setD(int,double)

setD

public boolean setD(int paramIndex,
                    double value)
Description copied from class: CS
sets a param to a double value. Same as P(paramIndex).setD(value)

Specified by:
setD in class CS

insertZ

public boolean insertZ(int paramIndex,
                       boolean value)
Overrides:
insertZ in class CS
See Also:
CS.insertD(int,double)

insertB

public boolean insertB(int paramIndex,
                       byte value)
Overrides:
insertB in class CS
See Also:
CS.insertD(int,double)

insertC

public boolean insertC(int paramIndex,
                       char value)
Overrides:
insertC in class CS
See Also:
CS.insertD(int,double)

insertS

public boolean insertS(int paramIndex,
                       short value)
Overrides:
insertS in class CS
See Also:
CS.insertD(int,double)

insertI

public boolean insertI(int paramIndex,
                       int value)
Overrides:
insertI in class CS
See Also:
CS.insertD(int,double)

insertJ

public boolean insertJ(int paramIndex,
                       long value)
Overrides:
insertJ in class CS
See Also:
CS.insertD(int,double)

insertF

public boolean insertF(int paramIndex,
                       float value)
Overrides:
insertF in class CS
See Also:
CS.insertD(int,double)

insertD

public boolean insertD(int paramIndex,
                       double value)
Description copied from class: CS
inserts a double as a param at a specific index. Same as insertP(paramIndex,new N(value))

Specified by:
insertD in class CS

toString

public java.lang.String toString()
problem: toString() does not return the same as L(String.class). toString returns code and L returns params as char values. Maybe only decompile() should be used for code instead.

Overrides:
toString in class java.lang.Object

javaCode

public java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
This will work with the basic operators like + / * - and probably a few others, but complex CSs will have to override this function to specify how to translate itself into Java code in combination with its children and descendent CSs.

Example:
CodeSimian code: *(+(2 3) /(4 5))
becomes this Java code: (2+3)*(4/5) There could be problems with Java's parsing order...

Overrides:
javaCode in class CS
Returns:
String of Java code, or null if this CS does not know how to convert itself to Java code.

setCountP

protected void setCountP(int newParamQuantity)

objectToCSArray

protected CS[] objectToCSArray(java.lang.Object o)
The default way to interpret an Object as a sequence of CSs.

All arrays are also Objects. This is mostly used for primitive-arrays, but its also useful for classes like String which is a sequence of char values.

Used in the default implementations of insertL and setL.

Returns null if doesnt know how to convert the Object to a CS[] array.

Currently does not work with Objects that are MULTI-DIMENSIONAL ARRAYS. One dimension or single Object.

If you have a more efficient way to set or insert certain param ranges without first converting to CS[] array, override insertL and/or setL to do that (else return super).


objectToCSArray

protected CS[] objectToCSArray(java.lang.Object o,
                               int arraySize)
Like objectToCSArray(Object) but requires the array be a certain size. If cant convert it to CS[] array, returns null.

By default, calls simply calls objectToCSArray(Object) and cuts off the end of the array if its too big and wraps around if its too small.


objectToCS

protected CS objectToCS(java.lang.Object o)
Tries to convert an Object to a CS, to be used by insertL1(Object,int) or setL1(Object,int) etc. Like objectToCSArray(Object) and objectToCSArray(Object,int) except only returns 1 CS. Returns null if cant convert to CS.


start

protected void start()
called by the default CS constructor (which has no parameters). Sets the options of this new CS, including root and addressShape.

start() might be moved into the default constructor, and a new constructor created that does nothing (for if subclass not want to call start).


setPrevExec

public void setPrevExec(double p)
Description copied from class: CS
rename to setPrevD. Move to DefaultCS with at most PROTECTED access (not public). Replace this function with setPrev(int negIndex, double d), and add a prev(int negIndex) function. Or something like that. I want to put in some set of functions that allow the previous (and future?) values of this CS to be found (and set in private?).

Specified by:
setPrevExec in class CS
See Also:
CS.prevD()

getObject

public java.lang.Object getObject()
Description copied from class: CS
Returns the main Object that this CS wraps. This function is deprecated and should be replaced with L(Object.class), which uses getObject(). Then getObject() should be completely removed. L(Class) is more flexible.

Overrides:
getObject in class CS
See Also:
anyObject

setObject

public boolean setObject(java.lang.Object setTo)
Description copied from class: CS
Sets the main Object that this CS wraps. This function is deprecated and should be replaced with set setL(setTo)

Overrides:
setObject in class CS
See Also:
anyObject

keyword

public java.lang.String keyword()
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Specified by:
keyword in class CS
See Also:
CS.parent(), CS.newInstance(), CS.name()