codesimian
Class TypeCheckedList

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
          extended by codesimian.NothingList
              extended by codesimian.TypeCheckedList
All Implemented Interfaces:
CodeSimian, java.io.Serializable

public class TypeCheckedList
extends NothingList

can only contain CSs that are the correct TYPE. Returns false if you try to add anything else. Type is defined by PType(int) for each param index, and is set by setPType(int,CS).

Example codesimian code:
do(
        typeCheckedList#theList(0 1 2 +(1 1 1) 4)
        func#typeChecker(0#x ==I(countP(x) 3)) "only accept things with 3 params"
        setPType(theList 3 typeChecker) "only allow things with 3 params in position 3"
        setP#work(theList 3 *(2 3 4)) "this should work because countP(*(2 3 4)) is 3"
        setP#fail(theList 3 *(2 3 4 5)) "this should fail because countP(*(2 3 4 5)) is 4"
        print("\nshouldWork = ") printD(work)
        print("\nshouldFail = ") printD(fail)
)

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
TypeCheckedList()
           
 
Method Summary
 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()".
 CS PType(int index)
          There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1.
 boolean setP(int index, CS value)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
 boolean setPType(int index, CS newTypeOfThatParam)
          Since only a small fraction of CSs use types other than the default type, setPType(int,CS) returns false by default.
 
Methods inherited from class codesimian.NothingList
DForProxy, javaCode, maxP, minP
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, description, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setPrevExec, setS, setZ, start, toString, V, 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, 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, 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

TypeCheckedList

public TypeCheckedList()
Method Detail

setP

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

Overrides:
setP in class DefaultCS

setPType

public boolean setPType(int index,
                        CS newTypeOfThatParam)
Description copied from class: CS
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.

Overrides:
setPType 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.

Overrides:
PType in class DefaultCS

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
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".

Overrides:
keyword in class NothingList
See Also:
CS.parent(), CS.newInstance(), CS.name()