codesimian
Class CS

java.lang.Object
  extended by codesimian.CS
All Implemented Interfaces:
CodeSimian
Direct Known Subclasses:
DefaultCS, IndependentCS

public abstract class CS
extends java.lang.Object
implements CodeSimian

CS is the root of all other classes! Its the top of the CodeSimian heirarchy. Everything you need to know to add new Java code To CodeSimian is in this file.

Theoretically some parts of CodeSimian code (created at runtime) will later be converted to Strings of Java code for a subclass of CS.java. The existing subclasses of CS (in many combinations) will generate new unique and useful subclasses of CS, and those subclasses will build even smarter subclasses.

Since it will be Turing-Complete, these subclasses will be flexible enough to contain a STRONG-ARTIFICIAL-INTELLIGENCE without stepping outside-the-box of CodeSimian. CodeSimian is designed to be used to create a Strong-AI that is BACKWARDS-COMPATIBLE with CodeSimian because it is an ancestor (subclass of a subclass...) of CS.java. Of course, such a software would be so advanced that it could only be created by automatically generated evolved code many generations above Java...

GNU General Public License (GPL) ************
LEGAL: By using CodeSimian, you agree to the GPL license,
version 2 or higher (your choice), in file license.txt.
CodeSimian is FREE for most people ***
but BUSINESSES must pay $$$ to USE A DIFFERENT LICENSE.
CodeSimian: Copyright 2006, Benjamin F Rayfield.
Websites: www.codesimian.com codesimian.sourceforge.net



All functions in CS are public and some are also abstract. There are no variables, only functions.

Each CS is a list of other CSs, and each subclass of CS uses the contents of the list differently.

Each CS has 1 main action: EXECUTE this CS. All of these functions can EXECUTE a CS: V() L(Class) L(int,Class,int) Z() B() C() S() I() J() F() and D(). Each does approximately the same thing, but with a different return-type. All types of primitive and array can be returned, and many object types. Different CSs can return different object types, many types per CS.

CS objects should use other CS objects only as type CS instead of their runtime-type, to avoid tangling CodeSimian with hard-code. Example: CS mult = new Multiply(); instead of: Multiply mult = new Multiply(); In codesimian code, 2 times 3 times 4 is written as: *(2 3 4) Any type-specific functions you need to call can be called dynamicly with a JavaMethod2 CS.

Functions whose names start with "set" return boolean. Most of them are allowed to ALWAYS RETURN FALSE, which would mean that feature is not available in the CS it is called from, but may be available in other CSs in the same group.

A TYPE is any primitive, Object, primitive[] array, Object[] array, or a CS containing any of those.
In addition to that, CodeSimian uses a more advanced idea of TYPE:
A TYPE is a CS whose minP() is at least 1, that measures the TYPE of its 1 param (the CS returned by theType.P(0)), and returns a more positive number if its more like that type, or 0 or less if it is not that type. Its like an anonymous fitness-function in a genetic-algorithm.

Some functions (that usually do the same thing) come in groups of 10-12, each for a different TYPE. Example: the EXECUTE functions above. Example: the PREV functions. Example: the setX functions where X is any EXECUTE function.


WHY SO MANY FUNCTIONS?
These 100+ functions seem confusing, but they are ordered on 3 dimensions+++
+ There are 4 main actions: SET, GET, INSERT, and DELETE.
+ There are 3 main targets: 1 CS in params, multiple adjacent CSs in params, the value of this CS.
+ TYPES. Multiply 3 x 4 x all the TYPES, and you get a 3D block of functions, where the location tells what the function does.
There is a hole in the cube at INSERT or DELETE x VALUE OF THIS CS.

Some functions like heap() and setHeap(CS) are not included in that cube. They're simply the GET and SET for variables that a CS should have, but are not copied for each TYPE. Theres only 1 get and 1 set. But these functions (like heap() and parsePriority()) are complicating CS.java, so they should eventually be changed to only be accessed by L("heap") setL("heap",someObject) etc. Only important functions, like myFuel() and name(), will remain hard-coded into CS.java.

Each CS is a list of CSs containing a quantity of CSs between minP() and maxP() and equal to countP(). All functions whose names contain a capital P (except "Proxy" "Parse" and "Parent") are about PARAMS (CSs inside this CS). Examples: P(int), PD(), setP(int,CS). Params are the contents of the list: Each CS is a list of other CSs.

Functions whose name contains a capital L allow Java Object types to be converted to and from CSs. L functions with 1 or more int parameters allow OPTIMIZATIONS for specific Object types.
Example: if some CS's params are represented as chars in a String (instead of a CS[] array) then that CS should override L(int i,Class c,int j) to return new S(String.substring(i,i+j)) if c == String.class; else return super.L(i,c,j); //S is a type of CS that is stored as a String in memory

WHY IS CS A CLASS INSTEAD OF AN INTERFACE?
I would have liked to make CS be an interface instead of an abstract class, for more flexibility in extending it, but I found that as a class it is approximately 30% faster than as an interface. Thats probably because as a class its functions are in known positions in the table of functions, but as an interface its functions could be in any position since the CLASS determines position, and functions must be looked up more DYNAMICLY which is slower. Not much has been lost: Since this class has approximately 100 functions, its unlikely anybody would use it as an interface except by automatic generation of Java code (see Reflect.java).

8/06 I'm working on the solution to the class/interface problem. CS implements interface CodeSimian, which contains only the most important functions. All other functions can be reflected in terms of these few functions. I've found some functions that must be included, but I've not decided all of which functions will be in the final CodeSimian.java, which is the most important file in CodeSimian software.

Many functions use this CS as a list of CSs. The default implementations are lazy and dont always throw IndexOutOfBoundsException's when they should.

5/06 I'm thinking about removing HEAP from class CS. Heap used negative indexs. It will still use negative indexs, but only hard-coded indexs like these...

public static final int NULL = -1;      
public static final int EXECPROXY = -2;
public static final int PREV = -3;
public static final int FUEL = -4; 
public static final int MYFUEL = -5;
public static final int NAME = -6;
public static final int NEWINSTANCE = -7;
public static final int PARENT = -8;
public static final int DESCRIPTION = -9;
public static final int PARSEPRIORITY = -10;
public static final int JAVACODE = -11;
public static final int HEAP = -12; 


Field Summary
static int DESCRIPTION
           
static int END
          the lowest negative index reserved for CS reflection.
static int EXECPROXY
          someCS.P(CS.EXECPROXY) should return someCS.getExec(),
and optionally someCS.setP(CS.EXECPROXY,x) (or other SET functions) should call someCS.setExec(x), but if the SET functions dont do that, they should return false in that case.
static int FUEL
           
static int HEAP
           
static int JAVACODE
           
static int MYFUEL
           
static int NAME
           
static int NEWINSTANCE
           
static int NULL
          NULL is returned, for example, by indexP(CS) when the CS cant be found.
static int PARENT
           
static int PARSEPRIORITY
           
static int PREV
           
static int TESTER
           
 
Constructor Summary
CS()
           
 
Method Summary
 CS addP(CS param)
          Adds a new param at the end of the list.
 CS addP(CS add0, CS add1)
          same as addP(add0) && addP(add1).
 CS addP(CS add0, CS add1, CS add2)
           
 CS addP(CS add0, CS add1, CS add2, CS add3)
           
 CS addP(CS add0, CS add1, CS add2, CS add3, CS add4)
           
 byte B()
           
 byte BForProxy()
           
 char C()
           
 char CForProxy()
           
 java.lang.Object clone()
          returns newInstance(), but if thats null then throws a CloneNotSupportedException This function overrides java.lang.Object.clone();
 double cost()
          cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively.
abstract  int countP()
          Quantity of params.
 double D()
          Execute this CS and cast to double.
abstract  boolean decrementMyFuel()
          Try to use 1 fuel credit.
abstract  boolean deleteP(int index)
          Deletes a Param at specified index, and slides the higher params down 1 index.
 boolean deleteP(int startIndex, int quantity)
          deletes a range of Params
abstract  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()
           
 float FForProxy()
           
abstract  CS fuel()
          Fuel limits EXECUTION of CSs, to make sure none execute too much more than the others.
abstract  CS getExec()
          Every CS must have an EXECPROXY (also called PROXY), even if its a trivial wrapper.
 java.lang.Object getObject()
          Deprecated.  
abstract  CS heap()
          HEAP is a place to put CSs that are not directly related to the CS that contains them.
 int I()
           
 int IForProxy()
           
 int indexP(CS myParam)
          Opposite of P(int).
Returns the index of the specified param, or -1 if its not a param here.
 int indexPName(java.lang.String paramName)
          returns the index of the Param with specified Name, or -1 if no Param has that Name.
 boolean insertB(int paramIndex, byte value)
           
 boolean insertC(int paramIndex, char value)
           
abstract  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)
           
abstract  boolean insertL(int startIndex, java.lang.Object insertMe)
          Inserts an Object into MULTIPLE param indexs.
abstract  boolean insertL(int startIndex, java.lang.Object insertMe, int indexQuantity)
          Inserts an Object into a specific subset of param indexs.
abstract  boolean insertL1(int singleIndex, java.lang.Object value)
          inserts an Object into 1 param index.
abstract  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)
           
 byte isIllusion(int index)
          Describes if the CS in an index is an illusion or not.
 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)
          using this CS as the root, returns this CS and its children recursively as a String of JAVA CODE that often (but not always) does the same thing as executing this root CS.
 java.lang.String javaCode(CS listOfCodeAlreadyTraversed, java.lang.Class returnType)
          similar to javaCode(CS) except Class returnType specifies what type the java code should have.
 long JForProxy()
           
abstract  java.lang.String keyword()
          Deprecated.  
 java.lang.Object L(java.lang.Class castToThisType)
          Deprecated. Use L(Object) instead.
 java.lang.Object L(int startIndex, java.lang.Class castToThisType, int indexQuantity)
          same as L(Class) except only uses a subset of param indexs.
Like many other L functions, allows optimizations of converting CSs to specific Object types.
Example: new S("abcdefg").L(2,String.class,3) returns "cde".
 java.lang.Object L(int startIndex, java.lang.Object castToThisType, int indexQuantity)
           
 java.lang.Object L(java.lang.Object key)
          This function will replace L(String) and L(Class)
and can do the same things as P(int) if "key" is a Number (uses Number.intValue()).
 java.lang.Object L(java.lang.String varName)
          Deprecated. replace me with L(Object) and setL(Object,Object)
abstract  java.lang.Object LForProxy(java.lang.Class castToThisType)
          The "?ForProxy" functions should only be called by a PROXY CS.
abstract  java.lang.Object LForProxy(int startIndex, java.lang.Class castToThisType, int indexQuantity)
           
 double maxD()
          maximum value D() can ever return (or any of the other primitive EXECUTE functions).
 int maxP()
          Maximum quantity of Params
 double minD()
          minimum value D() can ever return (or any of the other primitive EXECUTE functions).
abstract  int minP()
          Minimum quantity of Params.
abstract  int myFuel()
          Returns how many times this CS may EXECUTE before it needs to trade some CS fuel for int fuel.
abstract  java.lang.String name()
          returns the name of this CS.
abstract  CS newInstance()
          The primary way to instantiate subclasses of CS.
 byte overwrites(int index)
          Describes when (if ever) this CS overwrites one of its own childs.
abstract  CS P(int index)
          Returns a CS from this list with specific index.
 CS parent()
          9/06 parent() is not yet finished.
 int parsePriority()
          Returns the parsing priority of this CS type, in some language syntax, probably CodeSimian's.
 byte PB(int paramIndex)
           
 char PC(int paramIndex)
           
 double PD(int paramIndex)
          Returns a param as a double.
 float PF(int paramIndex)
           
 int PI(int paramIndex)
           
 long PJ(int paramIndex)
           
 java.lang.Object PL(int paramIndex, java.lang.Class castParamToThisType)
          PL PD PF PJ PI PS PC PB and PZ are only for convenience and optimization.
 byte prevB()
           
 char prevC()
           
abstract  double prevD()
          Returns the value of the last EXECUTION of this CS
 float prevF()
           
 int prevI()
           
 long prevJ()
           
abstract  java.lang.Object prevL()
          returns the previous execute value as an Object.
 short prevS()
           
 boolean prevZ()
          Returns true if the PREVIOUS EXECUTION of this CS was a positive number (or true).
 CS proxyOf(java.lang.reflect.Method anyMethodInThisClass)
          a proxy for a specific Java Method.
 short PS(int paramIndex)
           
abstract  CS PType(int indexP)
          There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1.
 boolean PZ(int paramIndex)
           
 java.lang.Object reflect(java.lang.Object[] nameAndParameters)
          Calls any function by reflection, including reflective functions on higher levels, reflection of reflection of reflection...
 java.lang.Object reflect(java.lang.String name, java.lang.Object[] parameters)
          same as reflect(Object[]) except the array is 1 smaller, and all indexs are 1 lower, and the first element which was taken out is String name,

This function is useful because it can use the same array as java.lang.reflect.Method.invoke(Object[]); Name should equal java.lang.reflect.Method.getName() of some Java function (Method).
 short S()
           
 boolean setB(byte setToThisValue)
           
 boolean setB(int paramIndex, byte value)
           
 boolean setC(char setToThisValue)
           
 boolean setC(int paramIndex, char value)
           
 boolean setCost(float cost)
          Rename this to setCostToExecute()
abstract  boolean setD(double setToThisValue)
           
abstract  boolean setD(int paramIndex, double value)
          sets a param to a double value.
 boolean setDescription(java.lang.String newDescription)
           
 boolean setExec(CS newExecProxy)
           
 boolean setF(float setToThisValue)
           
 boolean setF(int paramIndex, float value)
           
abstract  boolean setFuel(CS newFuel)
           
 boolean setHeap(CS newHeap)
           
 boolean setI(int setToThisValue)
           
 boolean setI(int paramIndex, int value)
           
 boolean setJ(int paramIndex, long value)
           
 boolean setJ(long setToThisValue)
           
abstract  boolean setL(int startIndex, java.lang.Object setToThisValue)
          Overwrites a range of params with some interpretation of the Object.
Like setL(int,Object,int) but the Object determines the quantity of indexs.
abstract  boolean setL(int startIndex, java.lang.Object setToThisValue, int indexQuantity)
          like setL(Object) but sets exactly the indexs between startIndex and startIndex+indexQuantity-1 inclusive
abstract  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 setL(java.lang.Object key, java.lang.Object value)
          Sets the value of something.
 boolean setL(java.lang.String varName, java.lang.Object value)
          Deprecated. replace me with L(Object) and setL(Object,Object)
 boolean setL1(int singleIndex, java.lang.Object value)
          overwrites 1 param with an Object.
abstract  boolean setMyFuel(int newValue)
           
 boolean setName(java.lang.String newName)
          sets the name of this CS
 boolean setObject(java.lang.Object setTo)
          Deprecated.  
abstract  boolean setP(int index, CS setTo)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
 boolean setParent(CS parent)
           
 boolean setParsePriority(int parsePriority)
           
abstract  void setPrevExec(double d)
          Deprecated.  
 boolean setProxyOf(java.lang.reflect.Method anyMethodInThisClass, CS proxy)
          sets the proxy of a Method.
 boolean setPType(int indexP, CS newTypeOfThatParam)
          Since only a small fraction of CSs use types other than the default type, setPType(int,CS) returns false by default.
 boolean setS(int paramIndex, short value)
           
 boolean setS(short setToThisValue)
           
 boolean setTester(CS tester)
          default: false
 boolean setZ(boolean setToThisValue)
           
 boolean setZ(int paramIndex, boolean value)
           
 short SForProxy()
           
 CS tester()
          Returns a CS that can test if this CS works correctly, or null if dont know how to test.
 void V()
           
 void VForProxy()
           
 void voidReflect(java.lang.Object[] returnAndNameAndParameters)
          Same as reflect(Object[]) except the array is 1 bigger, and returnAndNameAndParameters[0] is replaced by the return-value of the reflected function being called, and all indexs are 1 higher.
 boolean Z()
           
 boolean ZForProxy()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final int NULL
NULL is returned, for example, by indexP(CS) when the CS cant be found.

See Also:
Constant Field Values

EXECPROXY

public static final int EXECPROXY
someCS.P(CS.EXECPROXY) should return someCS.getExec(),
and optionally someCS.setP(CS.EXECPROXY,x) (or other SET functions) should call someCS.setExec(x), but if the SET functions dont do that, they should return false in that case.

There are others that work similarly: PREV, FUEL, NEWINSTANCE, PARENT, HEAP, NAME, DESCRIPTION, AND PARSEPRIORITY

See Also:
Constant Field Values

PREV

public static final int PREV
See Also:
Constant Field Values

FUEL

public static final int FUEL
See Also:
Constant Field Values

MYFUEL

public static final int MYFUEL
See Also:
Constant Field Values

NAME

public static final int NAME
See Also:
Constant Field Values

NEWINSTANCE

public static final int NEWINSTANCE
See Also:
Constant Field Values

PARENT

public static final int PARENT
See Also:
Constant Field Values

HEAP

public static final int HEAP
See Also:
Constant Field Values

DESCRIPTION

public static final int DESCRIPTION
See Also:
Constant Field Values

PARSEPRIORITY

public static final int PARSEPRIORITY
See Also:
Constant Field Values

JAVACODE

public static final int JAVACODE
See Also:
Constant Field Values

TESTER

public static final int TESTER
See Also:
Constant Field Values

END

public static final int END
the lowest negative index reserved for CS reflection.

If you call P(x) or setP(x,someCS) and CS.END <= x < 0 then it calls a get or set function. Example: setI(CS.MYFUEL,20) and setP(CS.MYFUEL,new N(20)) both call setMyFuel(20).

You may use any indexs lower than this for the HEAP, which is meant to contain "meta instance variables" for a CS which can be used automatically in CodeSimian code or by calling L(String) or setL(String,Object).

Some CSs will allow you to call setP(END-1,someCS) then P(END-1) == someCS.
The default way this is implemented is by using HEAP's params with positive indexs as negative indexs here. HEAP is any CS that can be a list of CSs, but thats not set-in-stone.

See Also:
Constant Field Values
Constructor Detail

CS

public CS()
Method Detail

P

public abstract CS P(int index)
Returns a CS from this list with specific index. Every CS is a list of other CSs, each with an index between 0 and countP()-1 inclusive. The quantity of CSs in the list is countP(), which should be between minP() and maxP() inclusive. Errors could occur if quantity is outside that range when this CS is EXECUTED.

There can also be CSs at negative indexs. Maps some negative indexs to the HEAP:
If x <= -2 then CS.P(x) returns CS.heap().P(-x). Index -1 represents NULL.

Parameters:
index - range 0 to countP()-1 inclusive
See Also:
heap()

setP

public abstract boolean setP(int index,
                             CS setTo)
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.


insertP

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


deleteP

public abstract boolean deleteP(int index)
Deletes a Param at specified index, and slides the higher params down 1 index.


deleteP

public boolean deleteP(int startIndex,
                       int quantity)
deletes a range of Params

Specified by:
deleteP in interface CodeSimian

minP

public abstract int minP()
Minimum quantity of Params. countP() may be below minP() only a short time during compiling, and you must not EXECUTE this CS during that time or you risk an error.


countP

public abstract int countP()
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.


maxP

public int maxP()
Maximum quantity of Params


indexP

public int indexP(CS myParam)
Opposite of P(int).
Returns the index of the specified param, or -1 if its not a param here.

This is needed for efficiency of finding params in CSs whose countP() is very large. For most CSs, countP() < 10, and a linear search should be fast enough, but for CSs that are used like huge arrays, indexP should use a CS-to-int hashtable.

This default implementation does not search the HEAP.


indexPName

public int indexPName(java.lang.String paramName)
returns the index of the Param with specified Name, or -1 if no Param has that Name.

This default implementation does not search the HEAP.

See Also:
name(), setName(String), indexP(CS)

PType

public abstract CS PType(int indexP)
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.


setPType

public boolean setPType(int indexP,
                        CS newTypeOfThatParam)
Since only a small fraction of CSs use types other than the default type, setPType(int,CS) returns false by default. The same is true of many other functions of CS, which may choose not to cooperate.


addP

public CS addP(CS param)
Adds a new param at the end of the list. Same as setP(countP(),param).

P means param. getP setP insertP and deleteP are the primary way to access params. addP must ALWAYS use those to access params. You should not set it up so any of those 4 use addP.

Returns 'this' CS so code like this works:
int ten = new Multiply().addP(new N(2),new N(5)).I();

Returns:
'this' CS if added param, or null if did not add.

addP

public CS addP(CS add0,
               CS add1)
same as addP(add0) && addP(add1).


addP

public CS addP(CS add0,
               CS add1,
               CS add2)
See Also:
addP(CS)

addP

public CS addP(CS add0,
               CS add1,
               CS add2,
               CS add3)
See Also:
addP(CS)

addP

public CS addP(CS add0,
               CS add1,
               CS add2,
               CS add3,
               CS add4)
See Also:
addP(CS)

PL

public java.lang.Object PL(int paramIndex,
                           java.lang.Class castParamToThisType)
                    throws CSCastException
PL PD PF PJ PI PS PC PB and PZ are only for convenience and optimization. Each gets P(int) then calls L(Class) D() F() etc on it, the second letter of that function's name.
PL(5,String.class) should return P(5).L(String.class) or something that gets the same result faster.

Throws:
CSCastException

PD

public double PD(int paramIndex)
Returns a param as a double. Same as P(paramIndex).D()

Why not just use P(paramIndex).D() instead? Its not just for convenience. Some CSs store their params as doubles or other primitives, and if you predict correctly how params are stored, PD(paramIndex) is much faster than P(paramIndex).D(), but BEWARE: if you predict incorrectly its a little slower. It calculates the same double either way.

For all paramIndex: P(paramIndex).D() == PD(paramIndex)
except when the function call causes params to change. Example: param is an instance of the Count class.


PF

public float PF(int paramIndex)
See Also:
PD(int)

PJ

public long PJ(int paramIndex)
See Also:
PD(int)

PI

public int PI(int paramIndex)
See Also:
PD(int)

PS

public short PS(int paramIndex)
See Also:
PD(int)

PC

public char PC(int paramIndex)
See Also:
PD(int)

PB

public byte PB(int paramIndex)
See Also:
PD(int)

PZ

public boolean PZ(int paramIndex)
See Also:
PD(int)

L

public java.lang.Object L(java.lang.Class castToThisType)
                   throws CSCastException
Deprecated. Use L(Object) instead.

Optionally execute this CS, and definitely try to CAST it to the specified Java type. If fail, throw a ClassCastException.

Should I change this from throwing a CSCastException to return null instead?

It is preferred not to return CSs from this function. If you have a CS to return, the standard is to put it in param0... setP(0,returnValue), where the function caller should get the output from... P(0).

The functions: V L Z B C S I J F and D, usually EXECUTE this CS and CAST its value to the specified type.
L does not have to execute this CS, but all the others do. The other difference is L can throw a CSCastException (extends ClassCastException), which is a RuntimeException so you do not have to use try/catch if you trust it.

No pattern of L()'s behavior is guaranteed.
The L's of some some CSs are more predictable than others, often written about in javadoc.
If it casts correctly, it could fail later. If it fails many times, and you try again, it could still succeed.

Example: new int[7][6][5].getClass().getName() returns "[[[I". These 9 function names (not 10 because excludes Void) are also used by a very important part of Java (but not as function names): java.lang.Class.name() .

EXAMPLES:
JButton b = (JButton) new ButtonCS().L(Component.class); //JButton inherits from Component
int fiveFiftyFive = new N(555).I();
double charValues[] = (double[]) new S("arraySize11").L(double[].class);

Throws:
CSCastException
See Also:
Z(), B(), C(), S(), I(), J(), F(), D()

LForProxy

public abstract java.lang.Object LForProxy(java.lang.Class castToThisType)
                                    throws CSCastException
The "?ForProxy" functions should only be called by a PROXY CS. They skip the proxy. Example: B() calls the PROXY on this CS, then that PROXY calls thisCS.BForProxy(). Generally, subclasses of CS should reimplement only the ?ForProxy functions.

Throws:
CSCastException
See Also:
execProxy(), setExecProxy(CS)

L

public java.lang.Object L(int startIndex,
                          java.lang.Object castToThisType,
                          int indexQuantity)
Specified by:
L in interface CodeSimian

L

public java.lang.Object L(int startIndex,
                          java.lang.Class castToThisType,
                          int indexQuantity)
                   throws CSCastException
same as L(Class) except only uses a subset of param indexs.
Like many other L functions, allows optimizations of converting CSs to specific Object types.
Example: new S("abcdefg").L(2,String.class,3) returns "cde".

Throws:
CSCastException

LForProxy

public abstract java.lang.Object LForProxy(int startIndex,
                                           java.lang.Class castToThisType,
                                           int indexQuantity)
                                    throws CSCastException
Throws:
CSCastException
See Also:
L(int,Class,int)

L

public java.lang.Object L(java.lang.String varName)
Deprecated. replace me with L(Object) and setL(Object,Object)

Reflects some of CS's functions as variables, and returns the value of a variable. Also returns variables that actually are variables (not reflected).

Returns a variable with specified name in the namespace of this CS. Returns null if no variable exists with that name.

Example: someCS.L("description") returns someCS.description(); Example: someCS.L("cost") returns someCS.cost();

STANDARD VARIABLE NAMES include name, cost, proxy, fuel, myFuel, description, newInstance, parent, parsePriority, heap, tester, prevD, etc. Returns the CS found by indexPName(varName) if varName is not a standard name.

FIX THE DESIGN OF CS.JAVA: Eventually description() and cost() should become protected or private (instead of public) and be completely replaced by L(String) and setL(String,Object), because class CS should have as few functions as possible. Its ok for CS to have lots of functions that interact with params, like PD(int), P(int), setD(int,double) etc, but some functions are best abstracted to a variable inside a CS instead of a required part of every CS. Its a little slower, but more efficient. For efficiency, functions like execProxy() and myFuel() etc will stay as functions, but can also be used by L("proxy") or setL("proxy",someProxyCS);

See Also:
Static.defaultVarNames(), Static.defaultVarTypes()

L

public java.lang.Object L(java.lang.Object key)
This function will replace L(String) and L(Class)
and can do the same things as P(int) if "key" is a Number (uses Number.intValue()).

The 3 most common key types are: Class, Integer, and Number. Some instances of all 3 work by default.

Specified by:
L in interface CodeSimian

setL

public boolean setL(java.lang.Object key,
                    java.lang.Object value)
Sets the value of something. Which thing is described by the KEY.

Key can be any Number between 0 and countP()-1, some Strings, or some Classes. Not all Strings and Classes work. Key may be any other Object, but CSs probably will not understand it unless you program them to. (today is 9/06) When more REFLECTION code is finished, this problem may be fixed, so any Object would work for key and value.

Specified by:
setL in interface CodeSimian
See Also:
L(Object)

V

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

VForProxy

public void VForProxy()
See Also:
DForProxy()

Z

public boolean Z()
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();\

ZForProxy

public boolean ZForProxy()
See Also:
DForProxy()

B

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

BForProxy

public byte BForProxy()
See Also:
DForProxy()

C

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

CForProxy

public char CForProxy()
See Also:
DForProxy()

S

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

SForProxy

public short SForProxy()
See Also:
DForProxy()

I

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

IForProxy

public int IForProxy()
See Also:
DForProxy()

J

public 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.

See Also:
L(Class), java.lang.Double.doubleToLongBits(double)

JForProxy

public long JForProxy()
See Also:
DForProxy()

F

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

FForProxy

public float FForProxy()
See Also:
DForProxy()

D

public double D()
Execute this CS and cast to double. All subclasses should override DForProxy() instead of D().

See Also:
L(java.lang.Class)

DForProxy

public abstract double DForProxy()
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()


minD

public double minD()
minimum value D() can ever return (or any of the other primitive EXECUTE functions). Default is -Double.MAX_VALUE, but functions like Math.sin(double) range from -1 to 1, so return -1.


maxD

public double maxD()
maximum value D() can ever return (or any of the other primitive EXECUTE functions). Default is Double.MAX_VALUE, but functions like Math.sin(double) range from -1 to 1, so return 1.


prevL

public abstract java.lang.Object prevL()
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.


prevZ

public boolean prevZ()
Returns true if the PREVIOUS EXECUTION of this CS was a positive number (or true).

See Also:
prevD()

prevB

public byte prevB()
See Also:
prevD()

prevC

public char prevC()
See Also:
prevD()

prevS

public short prevS()
See Also:
prevD()

prevI

public int prevI()
See Also:
prevD()

prevJ

public long prevJ()
See Also:
prevD()

prevF

public float prevF()
See Also:
prevD()

prevD

public abstract double prevD()
Returns the value of the last EXECUTION of this CS


setL

public abstract 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.


setD

public abstract boolean setD(double setToThisValue)

setF

public boolean setF(float setToThisValue)
See Also:
setD(double)

setJ

public boolean setJ(long setToThisValue)
See Also:
setD(double)

setI

public boolean setI(int setToThisValue)
See Also:
setD(double)

setS

public boolean setS(short setToThisValue)
See Also:
setD(double)

setC

public boolean setC(char setToThisValue)
See Also:
setD(double)

setB

public boolean setB(byte setToThisValue)
See Also:
setD(double)

setZ

public boolean setZ(boolean setToThisValue)
See Also:
setD(double)

setL1

public boolean setL1(int singleIndex,
                     java.lang.Object value)
              throws CSCastException
overwrites 1 param with an Object. Like setL(int,Object) but only uses 1 index. The easiest way to do this is put it in a CS and setP(singleIndex,that CS).

Specified by:
setL1 in interface CodeSimian
Throws:
CSCastException

setL

public abstract boolean setL(int startIndex,
                             java.lang.Object setToThisValue)
Overwrites a range of params with some interpretation of the Object.
Like setL(int,Object,int) but the Object determines the quantity of indexs.

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

setL

public boolean setL(java.lang.String varName,
                    java.lang.Object value)
Deprecated. replace me with L(Object) and setL(Object,Object)

Reflects some of CS's functions as variables, and sets those variables. Also sets variables that acually are variables (not reflected).

Sets (overwrites) the variable with specified name. STANDARD VARIABLE NAMES include name, cost, proxy, fuel, myFuel, description, newInstance, parent, parsePriority, heap, prevD, etc. Replaces the CS found by indexPName(varName) if varName is not a standard name.

FIX THE DESIGN OF CS.JAVA: Eventually description() and cost() should become protected or private (instead of public) and be completely replaced by L(String) and setL(String,Object), because class CS should have as few functions as possible. Its ok for CS to have lots of functions that interact with params, like PD(int), P(int), setD(int,double) etc, but some functions are best abstracted to a variable inside a CS instead of a required part of every CS. Its a little slower, but more efficient. For efficiency, functions like execProxy() and myFuel() etc will stay as functions, but can also be used by L("proxy") or setL("proxy",someProxyCS);

See Also:
Static.defaultVarNames(), Static.defaultVarTypes()

setL

public abstract boolean setL(int startIndex,
                             java.lang.Object setToThisValue,
                             int indexQuantity)
like setL(Object) but sets exactly the indexs between startIndex and startIndex+indexQuantity-1 inclusive

Specified by:
setL in interface CodeSimian

setZ

public boolean setZ(int paramIndex,
                    boolean value)
See Also:
setD(int,double)

setB

public boolean setB(int paramIndex,
                    byte value)
See Also:
setD(int,double)

setC

public boolean setC(int paramIndex,
                    char value)
See Also:
setD(int,double)

setS

public boolean setS(int paramIndex,
                    short value)
See Also:
setD(int,double)

setI

public boolean setI(int paramIndex,
                    int value)
See Also:
setD(int,double)

setJ

public boolean setJ(int paramIndex,
                    long value)
See Also:
setD(int,double)

setF

public boolean setF(int paramIndex,
                    float value)
See Also:
setD(int,double)

setD

public abstract boolean setD(int paramIndex,
                             double value)
sets a param to a double value. Same as P(paramIndex).setD(value)


insertL1

public abstract boolean insertL1(int singleIndex,
                                 java.lang.Object value)
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

insertL

public abstract boolean insertL(int startIndex,
                                java.lang.Object insertMe)
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
See Also:
insertL(int,Object,int)

insertL

public abstract boolean insertL(int startIndex,
                                java.lang.Object insertMe,
                                int indexQuantity)
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.


insertZ

public boolean insertZ(int paramIndex,
                       boolean value)
See Also:
insertD(int,double)

insertB

public boolean insertB(int paramIndex,
                       byte value)
See Also:
insertD(int,double)

insertC

public boolean insertC(int paramIndex,
                       char value)
See Also:
insertD(int,double)

insertS

public boolean insertS(int paramIndex,
                       short value)
See Also:
insertD(int,double)

insertI

public boolean insertI(int paramIndex,
                       int value)
See Also:
insertD(int,double)

insertJ

public boolean insertJ(int paramIndex,
                       long value)
See Also:
insertD(int,double)

insertF

public boolean insertF(int paramIndex,
                       float value)
See Also:
insertD(int,double)

insertD

public abstract boolean insertD(int paramIndex,
                                double value)
inserts a double as a param at a specific index. Same as insertP(paramIndex,new N(value))


newInstance

public abstract CS newInstance()
The primary way to instantiate subclasses of CS. CodeSimian is partially a PROTOTYPE LANGUAGE.

Copies the INSTANCE CS and pointers to its childs.
anyCS.P(2) == anyCS.newInstance().P(2)


anyCS.getClass() and anyCS.newInstance().getClass() do not have to share any ancestor class except CS.class. Classes that use artificial-intelligence may choose to return a different class type to improve themselves, but that class type should try to BEHAVE SIMILARLY and must have the SAME childs when newInstance() returns it.

If a subclass is uses variables in a strange way, it may need to override newInstance() to copy them.

Returns a new CS instance of this "type". This has the same name and purpose as java.lang.Class.newInstance().

Its vague. Subclasses of CS that have trees or networks of objects that the CS depends on might need to copy the whole tree etc, or might use the same tree, or only copy the root etc. Example: the Function class might need to override newInstance() differently.


parent

public CS parent()
9/06 parent() is not yet finished. CSs do not yet use parent(). They use keyword() instead of parent().name().

Returns the CS whose newInstance() created this CS, or returns a CS which this CS should think of as its parent.

No cycles may exist in parent().parent().parent()... paths.
One way to enforce this is to only do y.setParent(x) when x.newInstance() created y.

Recursive namespaces could be implemented by searching parent().parent()... until find the requested name. Could also search childs' parents recursively. Namespaces might search in many directions.

CS.keyword() will be replaced by CS.parent().name()

Returns:
the parent CS, or null if this CS was not created by an other CS. Returns null by default. You do not have to use the parent system.

setParent

public boolean setParent(CS parent)
See Also:
parent()

name

public abstract java.lang.String name()
returns the name of this CS.

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


setName

public boolean setName(java.lang.String newName)
sets the name of this CS


cost

public double cost()
cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively. The INTERNAL cost.

One unit of myFuel() costs cost() units of fuel(). Beware of CSs that counterfeit fuel.

Returns 1 by default.


setCost

public boolean setCost(float cost)
Rename this to setCostToExecute()

See Also:
cost()

description

public abstract java.lang.String description()
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.


setDescription

public boolean setDescription(java.lang.String newDescription)
See Also:
description()

parsePriority

public int parsePriority()
Returns the parsing priority of this CS type, in some language syntax, probably CodeSimian's. Default parsePriority is 0. Default CodeSimian parsePriorities use +100 or -100 increments, to allow many priorities to be inserted in the middle.

This will later be useful for infix syntax. Instead of: +(/(1 2) *(3 4 5)) you type: 1/2+3*4*5

Returns 0 by default.


setParsePriority

public boolean setParsePriority(int parsePriority)
See Also:
parsePriority()

getExec

public abstract CS getExec()
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


setExec

public boolean setExec(CS newExecProxy)
See Also:
getExec()

proxyOf

public CS proxyOf(java.lang.reflect.Method anyMethodInThisClass)
a proxy for a specific Java Method. getExec() (should be renamed to proxy()) returns the proxy for functions including D() C() I() L(Class) etc.

For all EXECUTE methods, proxyOf returns the same as getExec();

Each CS may have different proxies for different Methods or different quantity of proxies.

Except for the EXECUTE methods, most methods usually do not have a proxy, but you could design a subclass that used a proxy for every method if you wanted.

Returns:
the proxy, or null if there is no proxy for that Method

setProxyOf

public boolean setProxyOf(java.lang.reflect.Method anyMethodInThisClass,
                          CS proxy)
sets the proxy of a Method. Returns true if Method was an EXECUTE method and was able to overwrite (set) it, or false if did not.

For all EXECUTE methods, proxyOf returns the same as execProxy();

Each CS may have different proxies for different Methods or different quantity of proxies.

Except for the EXECUTE methods, most methods usually do not have a proxy, but you could design a subclass that used a proxy for every method if you wanted.

Returns:
true if the proxy of that Method (if any) could be replaced by (or created as) CS proxy

fuel

public abstract CS fuel()
Fuel limits EXECUTION of CSs, to make sure none execute too much more than the others. Fuel is ENFORCED by PROXYs, but each subclass of CS must be designed to defer all EXECUTE functions (V Z B C S I J F D L(Class) L(int,Class,int)) to the PROXY for that to work. In a proxy, the relationship between X and XForProxy (for all X) is different [I'll write more about that later]. Depending on which proxy you choose, it might decrease fuel and not execute "?ForProxy()" if fuel runs out.

There are 2 kinds of fuel. The CS fuel can be shared, and can distribute fuel in complex ways. The int fuel is individual to each CS.

This is the easiest (and slowest) way to use 1 fuel:
boolean usedFuel = fuel().setD( fuel().D() - cost() )

Fuel CSs must refuse to become negative. This code: fuel().setD(-3) must always return false.

fuel() should be changed to return CS instead of N (a subclass of CS)

WARNING: If you allow evolved code to modify fuel, it could steal or counterfeit fuel. Example CodeSimian code:
method#CodeSimian.CS.setFuel(0 someCounterfeitingCS 10000000000000)

When a CS's myFuel is decreased to 0, the only way it should ever EXECUTE again is if FUEL is TRADED for myFuel. One myFuel (type int) costs cost() (type double) amount of FUEL (type double, wrapped in a CS). That often allows the efficient use of the FUEL CS object, because you could trade many myFuels for more FUEL in the same amount of code as for trading one at a time. When a CS's myFuel runs out, you might set it up so it automatically buys 10 more, but only if some other code returns true. Certain groups of code could be allowed more execution credits depending on their expected usefulness, predicted by other intelligent code.

Can divide FUEL into heirarchies without extra code. Every CS has a FUEL object, and fuel objects are CSs, so every fuel object has a fuel object... When a fuel object runs out of fuel, it might try to get more from its fuel object... but that fuel object might refuse. A heirarchy of fuel control could be built.


setFuel

public abstract boolean setFuel(CS newFuel)
See Also:
fuel()

myFuel

public abstract int myFuel()
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.


setMyFuel

public abstract boolean setMyFuel(int newValue)
See Also:
myFuel()

decrementMyFuel

public abstract boolean decrementMyFuel()
Try to use 1 fuel credit. If true, pays for executing this CS once. returns false if myFuel() is 0 (or less, but it should never be less)

Same as setMyFuel(myFuel()-1) but faster.


javaCode

public java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
using this CS as the root, returns this CS and its children recursively as a String of JAVA CODE that often (but not always) does the same thing as executing this root CS. CodeSimian does not translate EXACTLY to Java, but simple code should translate ok. CSs that can not be converted to Java code should return null from this function.

IMPORTANT: the first thing this function must do (unless it returns null) is add the instance its called from to listOfCodeAlreadyTraversed, like this:
if(listOfCodeAlreadyTraversed.indexP(this) < 0) listOfCodeAlreadyTraversed.addP(this);

RETURNING NULL: A CS may return null from this function then when its called again return a String. Since each CS can only be used once, the CS may choose which call of this function (if more than 1) to cooperate.

Because CSs come in network/graph shapes instead of trees, this function has parameter that is a list of CSs that have already been converted to Java code so they wont be converted to code again possibly in an infinite loop.

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

javaCode

public java.lang.String javaCode(CS listOfCodeAlreadyTraversed,
                                 java.lang.Class returnType)
similar to javaCode(CS) except Class returnType specifies what type the java code should have. Example: javaCode(someCS,String.class) might return " \"a string\"+\"an other string\" ", and javaCode(someCS,double.class) should return something like (3+4+(5*Math.sin(x)*7)).

Primitive types like double.class and byte.class should create Java code that does the same thing as functions D() and B().

Class types that represent Objects or arrays should return the code that does the same thing as L(returnType).


overwrites

public byte overwrites(int index)
Describes when (if ever) this CS overwrites one of its own childs. Returns 1 if sometimes overwrites, 0 if dont know, or -1 if never overwrites.

Example, to overwrite index 2: setP(2,anyOtherCS) or setI(2,3);

Example: in bayesNode(list(..bayesnodes...) list(..numbers...)) the bayesNode modifies the numbers if they dont sum to 1.0 therefore bayesNode.overwrites(1) (second list) should return 1 (or 0) because it overwrites and bayesNode.overwrites(0) (first list) should return -1 (or 0) because it does not overwrite. WAIT A MINUTE... IF ITS ONLY MODIFIES ITS GRANDCHILDREN BUT NOT ITS CHILDS DIRECTLY, THEN WHY SHOULD THIS FUNCTION RETURN 1 FOR THE CHILDS INDEXS.

        Indexs can be positive (up to index countP()-1) or negative.
        Use any of:
        public static final int EXECPROXY = -2; 
        PREV = -3;
        FUEL = -4;
        MYFUEL = -5;
        NEWINSTANCE = -6;
        PARENT = -7;
        NAME = -8;
        DESCRIPTION = -9;
        PARSEPRIORITY = -10;
        JAVACODE = -11;
        HEAP = -12;


Overwrites() can theoretically be used for optimization of code. If you know some param is never overwritten by the CS that contains it, then only external CSs can do it. If they dont, its never overwritten, and can be optimized.

Returns:
1 if sometimes overwrites index, 0 if doesnt know, -1 if never overwrites

isIllusion

public byte isIllusion(int index)
Describes if the CS in an index is an illusion or not. Example (S extends CS): new S("8fakeCSs") contains a String containing 8 chars. It only appears to contain 8 CSs. new S("8fakeCSs").P(3) returns the same as Const.pool('k'); //P(4).C() == 'e' Therefore S should override isIllusion to return 1 for every index.

Since illusions are constantly overwritten (to give the illusion that they change), if isIllusion(x)==1 then it must be true that: overwrites(x)==1 or overwrites(x)==0. It may equal 0 because that says you dont know (even though it is true).

See Also:
overwrites(int), S.isIllusion(int)

heap

public abstract CS heap()
HEAP is a place to put CSs that are not directly related to the CS that contains them. Example: Params are directly relevant, but wrappers for the Java functions of a CS (like heap()) are not.

If you think of the positive (Param) indexs as STACK memory, this is HEAP memory and is mapped to negative param indexs.
Index 0 is grouped with the positives. Index -1 is reserved for NULL.
Heap indexs start at -2, which maps to index 2 in the HEAP. The heap's first 2 indexs are not used.


If x <= -2 then CS.P(x) returns CS.heap().P(-x)

Every CS must have a HEAP, which is used like heap memory (compared to stack memory). Multiple CSs can share the same HEAP or each could have its own. Only nonnegative P indexs are used for the heap, but they're usually mapped to negative indexs in the CS(s) that use this HEAP.

Usually HEAPs contain reflected java functions for the class of the CS that contains this HEAP. Some HEAPs might contain other variables.


setHeap

public boolean setHeap(CS newHeap)
See Also:
heap()

tester

public CS tester()
Returns a CS that can test if this CS works correctly, or null if dont know how to test. This function lets tests be run in a more organized and dynamic way if each important CS will define its own tester CS (inner class?). Returns null by default.

See Also:
#setTester()

setTester

public boolean setTester(CS tester)
default: false

See Also:
tester()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
returns newInstance(), but if thats null then throws a CloneNotSupportedException This function overrides java.lang.Object.clone();

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

reflect

public java.lang.Object reflect(java.lang.Object[] nameAndParameters)
Description copied from interface: CodeSimian
Calls any function by reflection, including reflective functions on higher levels, reflection of reflection of reflection...

        THE FOLLOWING CODE NEEDS TO BE CHECKED FOR RECURSIVE ARRAY ERRORS...
        

//These 4 examples do the same thing, but with increasing levels of reflection... Boolean setLReturnedTrue1 = new Boolean( someCS.setL(2,"countP",3) ); Boolean setLReturnedTrue2 = (Boolean) someL.reflect( new Object[]{"setL", new Integer(2), "countP", new Integer(3)} ); Boolean setLReturnedTrue3 = (Boolean) someL.reflect( new Object[]{ "reflect", new Object[]{"setL", new Integer(2), "countP", new Integer(3)} } ); Boolean setLReturnedTrue4 = (Boolean) someL.reflect( new Object[]{ "reflect", new Object[]{ "reflect", new Object[]{"setL", new Integer(2), "countP", new Integer(3)} } } ); Boolean setLReturnedTrue5 = (Boolean) someL.reflect( new Object[]{ "reflect", new Object[]{ "reflect", new Object[]{ "reflect", new Object[]{"setL", new Integer(2), "countP", new Integer(3)} } } } ); //Infinite reflection...


If this L is a CS, it should also reflect the functions in CS.

The easiest and most general way to do this is by using the java.lang.reflect package, but

Specified by:
reflect in interface CodeSimian

reflect

public java.lang.Object reflect(java.lang.String name,
                                java.lang.Object[] parameters)
Description copied from interface: CodeSimian
same as reflect(Object[]) except the array is 1 smaller, and all indexs are 1 lower, and the first element which was taken out is String name,

This function is useful because it can use the same array as java.lang.reflect.Method.invoke(Object[]); Name should equal java.lang.reflect.Method.getName() of some Java function (Method).

Specified by:
reflect in interface CodeSimian

voidReflect

public void voidReflect(java.lang.Object[] returnAndNameAndParameters)
Description copied from interface: CodeSimian
Same as reflect(Object[]) except the array is 1 bigger, and returnAndNameAndParameters[0] is replaced by the return-value of the reflected function being called, and all indexs are 1 higher.

This is useful if you want to store everything about a function-call together in 1 array.

EFFICIENCY: Depending on the object, reflect(Object[]) or voidReflect(Object[]) may be a little more efficient than the other, even though they do the same thing, because usually reflect calls voidReflect or voidReflect calls reflect.

        //USE THIS CODE IF YOU'RE LAZY (interfaces cant contain code):  
        public void voidReflect(Object returnAndNameAndParameters[]){
                Object nameAndParams[] = new Object[returnAndNameAndParameters.length-1];
                //Insert code here to modify nameAndParams, if you want.
                System.arraycopy(nameAndParams, 0, returnAndNameAndParameters, 1, nameAndParams.length);
                returnAndNameAndParameters[0] = reflect(nameAndParams);
        }
        

Specified by:
voidReflect in interface CodeSimian

setPrevExec

public abstract void setPrevExec(double d)
Deprecated. 

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?).

See Also:
prevD()

getObject

public java.lang.Object getObject()
Deprecated. 

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.

See Also:
L(Class)

setObject

public boolean setObject(java.lang.Object setTo)
Deprecated. 

Sets the main Object that this CS wraps. This function is deprecated and should be replaced with set setL(setTo)


keyword

public abstract java.lang.String keyword()
Deprecated. 

Returns the keyword of this CS or (after more code is finished) returns parent().name();

Keyword() needs to be removed. Keyword() can only be removed from CS.java when the primary way to instantiate the default CS types is by using newInstance() on one of the CSs in a list of default CSs.

When you instantiate someCS with someCS.parent().newInstance(), someCS.keyword() can be replaced by someCS.parent().name().

keyword() appears in the code hundreds of times. Be careful when refactoring it out.

There is intentionally no setKeyword(String) in this interface. Dont add it.

See Also:
parent(), newInstance(), name()