Reference
Reference
|
Reference
Data Types
n: Numeric scalar. Entered as a number, e.g. 5.2.
nv: Numeric vector. A scalar may be used instead. Entered in
the format (1 2 3 4 5).
c: Character scalar. Entered as 'a'
cv: Character vector, or string. A scalar may be used instead.
Entered as 'hello world!'
block: Function block. Entered as { blockdef }.
Function blocks may be nested.
array: An array which can contain elements of any type, including other arrays. Entered
as [item1 item2 ... itemn].
bool: Boolean scalar: numeric scalar compared against 0 (false).
Basic Operators
nv nv +: Adds the top two elements of the stack.
nv nv -: Subtracts the top of the stack from the penultimate;
e.g 2 1 - gives 1.
nv nv *: Multiplies the top two elements of the stack.
nv nv /: Divides the top of the stack by the penultimate;
e.g. (4 6)(2 2) / gives (2 3).
nv nv ^: Raises the second element on the stack to the power of the first: 2 3 ^ gives 8.
nv nv <, >, <=, >=: Conditional operators for numerics.
obj1 obj2 =, !=: Equality operators.
nv nv &: Ands the top two elements of the stack,
using 0 as false and other values as true; e.g. (1 0 3 2 -1)(2 1 0 -2 -2)&
gives (1 0 0 1 1).
nv nv |: Ors the top two elements of the stack,
using 0 as false and other values as true; e.g. (0 0 2 0 -2)(2 0 0 3 99)&
gives (1 0 1 1 1).
nv ~: Negates the top of the stack, using 0 as false and other
values as true.
nv \+: Plus reduce on the vector: (4 2 1)\+ gives 7.
nv \-: Minus reduce on the vector:
(4 2 1)\- gives 1 (4 - 2 - 1).
nv \*: Times reduce on the vector:
(4 2 1)\* gives 8.
nv \/: Divide reduce on the vector:
(4 2 1)\- gives 2 ((4 / 2) / 1).
nv \,: Turns a vector into simple scalars on stack.
nv/cv nv/cv , (not implemented yet!): Catenates top two elements of stack.
Types must be the same.
obj obj ;: Catenates the string representations of the two objects, leaving a string on the stack.
nv ?: For each element of nv, produces a random
number between 1 and that element.
//: Comment until end of line
# Functions
obj1 obj2 ... objn n #apush: Stores obj1 etc. in an n-element array.
array #apop: Puts the contents of array on the stack.
#clear: Clears the workspace, deleting all functions, variables, namespaces and dictionaries.
#clearstatus: Clears the user status field.
#cls: Clears the output window.
nv #complement: Returns the bitwise complement of each element of nv.
cv #cs: Sets the current namespace to cv relative to the root.
#curns: Puts the name of the current namespace (as it would be entered to #cs) on
the stack. If in the root namespace, this will be the empty vector ('').
obj #d: Duplicates top of stack.
cv block #def: Define function cv as block.
cv #ed: Edits function cv.
obj1 obj2 #eq: Removes the items from the stack, and leaves
a boolean vector of the same length indicating whether each element matches
its counterpart.
cv #erase or #kill: erase variable, function or object cv.
cv #error: Signals an error with message cv.
obj1 obj2 #exch: Exchanges the top two elements of the stack.
cv #exec: Executes cv using the standard parser.
#exit: Breaks out of the innermost loop.
#fns: Shows the list of function in the current space.
ns ni ne block #for: Runs block for each value between ns and
ne using a step of ni, pushing the current value onto the stack each time. If the
procedure defined in block does not use or pop this value, it will accumulate on the stack. For example:
0 1 5 { } #for
... will produce the output ...
0 1 2 3 4 5.
nv/cv block #forall: Executes block for each item in the vector, pushing the element first.
If the procedure does not use or pop this value, it will accumulate on the stack. For example:
(1 2 3 4 5) { } #forall
... will produce the output ...
1 2 3 4 5.
Note that { } #forall has the same effect as \,.
nv/cv1 nv2 #get: Selects nv2 from nv/cv1:
(1 2 3 4)(2 3)#get gives (2 3).
#getstatus: Returns the text in the user status field.
#getsysstatus: Returns the text in the system status field. Note that at the moment this
will always give 'Running', as this is displayed whenever any function or code is run.
n #i: Iota-n: 5 #i gives (1 2 3 4 5).
bool block #if: If bool is not 0, run block.
bool block1 block2 #ifelse: If bool is not 0, run block1,
otherwise run block2.
cv #loadscript: see #run below.
block #loop: Repeatedly runs block until a call to #exit.
n #math.sin: Sine of an angle (in degrees)
n #math.cos: Cosine of an angle
n #math.tan: Tangent of an angle
n #math.arcsin: Reverse sine: gives angle
n #math.arccos: Reverse cosine: gives angle
n #math.arctan: Reverse tangent: gives angle
#null: Adds a null to the stack.
cv1 cv2 nv1 nv2 n cv3 cv4 #o (not implemented yet!): Create object.
obj #pop: Removes the top of the stack.
#pushdict: Pushes a new dictionary onto the dictionary stack. A dictionary is an integral block of
functions, variables and namespaces, which can view items in dictionaries further up the stack. The dictionary is preserved
until a call to #popdict.
#popdict: Pops the top dictionary from the top of the stack, erasing all the contents of that dictionary and freeing
associated resources. You cannot #popdict the base dictionary.
n block #repeat: Repeats block n times.
cv/nv n #resize: Resizes cv/nv to be n items long.
objn ... obj0 n1 n2 #roll: Rotates the top n1 elements of the stack n2 places
to the right. If n2 is negative, they are rotated left. For example:
'a' 'b' 'c' 3 -1 #roll
... gives ...
'b' 'c' 'a'.
cv/nv #reverse: Reverses the vector.
cv #run: Runs script cv using the standard R parser.
cv #save or #savescript: Saves the current space as a runnable script file of name cv.
cv obj #set: Define variable cv as obj.
cv #setstatus: Sets the text in the user status field.
obj #size: Removes obj from the stack, and leaves its size.
#spaces: Shows the list of all namespaces, as they would be entered to
#cs (based in root).
#stacksize or #stacklength: Size of the stack.
obj #totext: Removes obj from the stack, and leaves a text representation.
obj #type: Adds the type of obj to the stack. The types are:
n
nv
c
cv
block
array
Note that a null gives 0, and a [ (start of array) gives -6.
n1 n2 ... nn n #v: Stores obj1 etc. in an n-element numeric vector.
#vars: Shows the list of variables in the current space.
#view: View the stack.
#x: Clear the stack.
Page and site © Richard Smith 2001
Please send any comments to richard@redcorona.com - thank you.
|