|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.iu.cnets.klatsch.lang.Value
edu.iu.cnets.klatsch.lang.VPrimitive
public class VPrimitive
This class encapsulates primitive functions.
The exact mechanism is a little strange, so read this carefully! To create a new primitive, all you
need to do is declare a new method "Value prim_NAME(Value[] args)", and the Runtime
class
will automatically take care of adding it to the base environment using reflection. It does that by
creating an instance of VPrimitive for each primitive that's set up to call that particular primitive.
That's the only place this class ever needs to be instantiated.
Field Summary | |
---|---|
(package private) java.lang.String |
name
the name of the primitive |
(package private) java.lang.reflect.Method |
prim
the method to invoke |
Constructor Summary | |
---|---|
VPrimitive(java.lang.String name,
java.lang.reflect.Method prim)
Create a new primitive wrapper for a primitive that has the given name and is implemented by the given method. |
Method Summary | |
---|---|
Value |
apply(Value... args)
Invoke the primitive for which we were instantiated. |
Value |
prim_abs(Value... args)
abs(n) : Returns the absolute value of n. |
Value |
prim_acos(Value... args)
acos(n) : Returns the arc cosine (in radians) of n. |
Value |
prim_anode(Value... args)
anode(n) : Creates a new actor node with ID n. |
Value |
prim_asin(Value... args)
asin(n) : Returns the arc sine (in radians) of n. |
Value |
prim_atan(Value... args)
atan(n) : Returns the arc tangent (in radians) of n. |
Value |
prim_atan2(Value... args)
atan2(y, x) : Returns the arc tangent (in radians) of the value y/x. |
Value |
prim_bench(Value... args)
bench(p) : Evaluates the given thunk for timing information. |
Value |
prim_ceil(Value... args)
ceil(n) : Returns the ceiling of n. |
Value |
prim_cos(Value... args)
cos(n) : Returns the cosine of n, with n in radians. |
Value |
prim_edge(Value... args)
edge(n1, n2) : Creates a new edge from node n1 to node n2 (when = now, weight = 1). |
Value |
prim_exec(Value... args)
exec(s) : Executes a script in the current environment. |
Value |
prim_exit(Value... args)
exit() : Exits the Klatsch interpreter. |
Value |
prim_exp(Value[] args)
exp(n) : Returns e^n. |
Value |
prim_feed(Value... args)
feed(s) : Returns a new feed of type s, using default values. |
Value |
prim_floor(Value... args)
floor(n) : Returns the floor of n. |
Value |
prim_graph(Value... args)
graph() : Creates a new graph. |
Value |
prim_grapher(Value... args)
grapher(n, p) : Creates a new Erdos-Renyi random graph with n nodes and edge probability p. |
Value |
prim_json(Value... args)
json(v) : Returns a JSON-parsable version of the given value. |
Value |
prim_list(Value... args)
list(n) : Returns a list pre-allocated to have n slots. |
Value |
prim_log(Value... args)
log(n) : Returns log base e of n. |
Value |
prim_log10(Value... args)
log10(n) : Returns log base 10 of n. |
Value |
prim_mnode(Value... args)
mnode(n) : Creates a new meme node with ID n. |
Value |
prim_pane(Value... args)
pane(s) : Returns a new pane of type s, using default values. |
Value |
prim_print_err(Value... args)
print_err(v1, ...) : Prints v1, ... |
Value |
prim_print(Value... args)
print(v1, ...) : Prints v1, ... |
Value |
prim_println_err(Value... args)
println_err(v1, ...) : Prints v1, ..., and a newline to the error console. |
Value |
prim_println(Value... args)
println(v1, ...) : Prints v1, ..., and a newline to the console. |
Value |
prim_queue(Value... args)
queue() : Returns a new, empty queue. |
Value |
prim_random(Value... args)
random() : Returns a random number between 0 and 1. |
Value |
prim_range(Value... args)
range(end) : Returns a stream ranging from 1 to end, inclusive range(start, end) : Returns a stream ranging from start to end, inclusive range(start, end, step) : Returns a stream ranging from start to end, stepping by step. |
Value |
prim_round(Value... args)
round(n) : Returns the result of rounding n to the nearest integer. |
Value |
prim_sign(Value... args)
sign(n) : Returns the sign of n (-1, 0, or 1). |
Value |
prim_sin(Value... args)
sin(n) : Returns the sine of n, with n in radians. |
Value |
prim_sqrt(Value... args)
sqrt(n) : Returns the square root of n. |
Value |
prim_stack(Value... args)
stack() : Returns a new, empty stack. |
Value |
prim_tan(Value... args)
tan(n) : Returns the tangent of n, with n in radians. |
Value |
prim_test(Value... args)
test() : General-purpose testing primitive for the feature du jour. |
java.lang.String |
toString()
Returns a string representation of the primitive. |
Methods inherited from class edu.iu.cnets.klatsch.lang.Value |
---|
require, requireCount, requireType, toJson |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
java.lang.String name
java.lang.reflect.Method prim
Constructor Detail |
---|
public VPrimitive(java.lang.String name, java.lang.reflect.Method prim)
name
- the primitive nameprim
- the primitive implementationMethod Detail |
---|
public Value apply(Value... args) throws EvaluationException
apply
in interface Callable
args
- the arguments to pass in
EvaluationException
- for any runtime errorspublic java.lang.String toString()
toString
in class Value
public Value prim_abs(Value... args) throws EvaluationException
EvaluationException
public Value prim_acos(Value... args) throws EvaluationException
EvaluationException
public Value prim_anode(Value... args) throws EvaluationException
EvaluationException
public Value prim_asin(Value... args) throws EvaluationException
EvaluationException
public Value prim_atan(Value... args) throws EvaluationException
EvaluationException
public Value prim_atan2(Value... args) throws EvaluationException
EvaluationException
public Value prim_bench(Value... args) throws EvaluationException
EvaluationException
public Value prim_ceil(Value... args) throws EvaluationException
EvaluationException
public Value prim_cos(Value... args) throws EvaluationException
EvaluationException
public Value prim_edge(Value... args) throws EvaluationException
EvaluationException
public Value prim_exec(Value... args) throws EvaluationException
EvaluationException
public Value prim_exit(Value... args) throws EvaluationException
EvaluationException
public Value prim_exp(Value[] args) throws EvaluationException
EvaluationException
public Value prim_feed(Value... args) throws EvaluationException
EvaluationException
public Value prim_floor(Value... args) throws EvaluationException
EvaluationException
public Value prim_graph(Value... args) throws EvaluationException
EvaluationException
public Value prim_grapher(Value... args) throws EvaluationException
EvaluationException
public Value prim_json(Value... args) throws EvaluationException
EvaluationException
public Value prim_list(Value... args) throws EvaluationException
EvaluationException
public Value prim_log(Value... args) throws EvaluationException
EvaluationException
public Value prim_log10(Value... args) throws EvaluationException
EvaluationException
public Value prim_mnode(Value... args) throws EvaluationException
EvaluationException
public Value prim_pane(Value... args) throws EvaluationException
EvaluationException
public Value prim_print(Value... args) throws EvaluationException
EvaluationException
public Value prim_print_err(Value... args) throws EvaluationException
EvaluationException
public Value prim_println(Value... args) throws EvaluationException
EvaluationException
public Value prim_println_err(Value... args) throws EvaluationException
EvaluationException
public Value prim_queue(Value... args) throws EvaluationException
EvaluationException
public Value prim_random(Value... args) throws EvaluationException
EvaluationException
public Value prim_range(Value... args) throws EvaluationException
EvaluationException
public Value prim_round(Value... args) throws EvaluationException
EvaluationException
public Value prim_sign(Value... args) throws EvaluationException
EvaluationException
public Value prim_sin(Value... args) throws EvaluationException
EvaluationException
public Value prim_sqrt(Value... args) throws EvaluationException
EvaluationException
public Value prim_stack(Value... args) throws EvaluationException
EvaluationException
public Value prim_tan(Value... args) throws EvaluationException
EvaluationException
public Value prim_test(Value... args) throws EvaluationException
EvaluationException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |