edu.iu.cnets.klatsch.lang
Class VPrimitive

java.lang.Object
  extended by edu.iu.cnets.klatsch.lang.Value
      extended by edu.iu.cnets.klatsch.lang.VPrimitive
All Implemented Interfaces:
Callable

public class VPrimitive
extends Value
implements Callable

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

name

java.lang.String name
the name of the primitive


prim

java.lang.reflect.Method prim
the method to invoke

Constructor Detail

VPrimitive

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

Parameters:
name - the primitive name
prim - the primitive implementation
Method Detail

apply

public Value apply(Value... args)
            throws EvaluationException
Invoke the primitive for which we were instantiated.

Specified by:
apply in interface Callable
Parameters:
args - the arguments to pass in
Returns:
the return value
Throws:
EvaluationException - for any runtime errors

toString

public java.lang.String toString()
Returns a string representation of the primitive.

Specified by:
toString in class Value
Returns:
the string

prim_abs

public Value prim_abs(Value... args)
               throws EvaluationException
abs(n) : Returns the absolute value of n.

Throws:
EvaluationException

prim_acos

public Value prim_acos(Value... args)
                throws EvaluationException
acos(n) : Returns the arc cosine (in radians) of n.

Throws:
EvaluationException

prim_anode

public Value prim_anode(Value... args)
                 throws EvaluationException
anode(n) : Creates a new actor node with ID n.

Throws:
EvaluationException

prim_asin

public Value prim_asin(Value... args)
                throws EvaluationException
asin(n) : Returns the arc sine (in radians) of n.

Throws:
EvaluationException

prim_atan

public Value prim_atan(Value... args)
                throws EvaluationException
atan(n) : Returns the arc tangent (in radians) of n. Note: atan2(y, x) is better and you should really use it instead.

Throws:
EvaluationException

prim_atan2

public Value prim_atan2(Value... args)
                 throws EvaluationException
atan2(y, x) : Returns the arc tangent (in radians) of the value y/x.

Throws:
EvaluationException

prim_bench

public Value prim_bench(Value... args)
                 throws EvaluationException
bench(p) : Evaluates the given thunk for timing information.

Throws:
EvaluationException

prim_ceil

public Value prim_ceil(Value... args)
                throws EvaluationException
ceil(n) : Returns the ceiling of n.

Throws:
EvaluationException

prim_cos

public Value prim_cos(Value... args)
               throws EvaluationException
cos(n) : Returns the cosine of n, with n in radians.

Throws:
EvaluationException

prim_edge

public Value prim_edge(Value... args)
                throws EvaluationException
edge(n1, n2) : Creates a new edge from node n1 to node n2 (when = now, weight = 1). edge(n1, n2, w) : Additionally specifies a weight. edge(n1, n2, w, t) : Additionally specifies a weight and trusted weight. edge(n1, n2, s, e, w, t) : Additionally specifies start and end times.

Throws:
EvaluationException

prim_exec

public Value prim_exec(Value... args)
                throws EvaluationException
exec(s) : Executes a script in the current environment.

Throws:
EvaluationException

prim_exit

public Value prim_exit(Value... args)
                throws EvaluationException
exit() : Exits the Klatsch interpreter.

Throws:
EvaluationException

prim_exp

public Value prim_exp(Value[] args)
               throws EvaluationException
exp(n) : Returns e^n.

Throws:
EvaluationException

prim_feed

public Value prim_feed(Value... args)
                throws EvaluationException
feed(s) : Returns a new feed of type s, using default values. feed(s, dict) : Returns a new feed of type s, using the given configuration dictionary. This translates to calling a constructor for edu.iu.cnets.klatsch.feed.[s] with dict as a parameter.

Throws:
EvaluationException

prim_floor

public Value prim_floor(Value... args)
                 throws EvaluationException
floor(n) : Returns the floor of n.

Throws:
EvaluationException

prim_graph

public Value prim_graph(Value... args)
                 throws EvaluationException
graph() : Creates a new graph.

Throws:
EvaluationException

prim_grapher

public Value prim_grapher(Value... args)
                   throws EvaluationException
grapher(n, p) : Creates a new Erdos-Renyi random graph with n nodes and edge probability p.

Throws:
EvaluationException

prim_json

public Value prim_json(Value... args)
                throws EvaluationException
json(v) : Returns a JSON-parsable version of the given value.

Throws:
EvaluationException

prim_list

public Value prim_list(Value... args)
                throws EvaluationException
list(n) : Returns a list pre-allocated to have n slots.

Throws:
EvaluationException

prim_log

public Value prim_log(Value... args)
               throws EvaluationException
log(n) : Returns log base e of n.

Throws:
EvaluationException

prim_log10

public Value prim_log10(Value... args)
                 throws EvaluationException
log10(n) : Returns log base 10 of n.

Throws:
EvaluationException

prim_mnode

public Value prim_mnode(Value... args)
                 throws EvaluationException
mnode(n) : Creates a new meme node with ID n.

Throws:
EvaluationException

prim_pane

public Value prim_pane(Value... args)
                throws EvaluationException
pane(s) : Returns a new pane of type s, using default values. pane(s, dict) : Returns a new pane of type s, using the given configuration dictionary. This translates to calling a constructor for edu.iu.cnets.klatsch.pane.[s] with dict as a parameter.

Throws:
EvaluationException

prim_print

public Value prim_print(Value... args)
                 throws EvaluationException
print(v1, ...) : Prints v1, ... to the console.

Throws:
EvaluationException

prim_print_err

public Value prim_print_err(Value... args)
                     throws EvaluationException
print_err(v1, ...) : Prints v1, ... to the error console.

Throws:
EvaluationException

prim_println

public Value prim_println(Value... args)
                   throws EvaluationException
println(v1, ...) : Prints v1, ..., and a newline to the console.

Throws:
EvaluationException

prim_println_err

public Value prim_println_err(Value... args)
                       throws EvaluationException
println_err(v1, ...) : Prints v1, ..., and a newline to the error console.

Throws:
EvaluationException

prim_queue

public Value prim_queue(Value... args)
                 throws EvaluationException
queue() : Returns a new, empty queue.

Throws:
EvaluationException

prim_random

public Value prim_random(Value... args)
                  throws EvaluationException
random() : Returns a random number between 0 and 1. random(n) : Returns a random number between 0 and n.

Throws:
EvaluationException

prim_range

public Value prim_range(Value... args)
                 throws EvaluationException
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.

Throws:
EvaluationException

prim_round

public Value prim_round(Value... args)
                 throws EvaluationException
round(n) : Returns the result of rounding n to the nearest integer.

Throws:
EvaluationException

prim_sign

public Value prim_sign(Value... args)
                throws EvaluationException
sign(n) : Returns the sign of n (-1, 0, or 1).

Throws:
EvaluationException

prim_sin

public Value prim_sin(Value... args)
               throws EvaluationException
sin(n) : Returns the sine of n, with n in radians.

Throws:
EvaluationException

prim_sqrt

public Value prim_sqrt(Value... args)
                throws EvaluationException
sqrt(n) : Returns the square root of n.

Throws:
EvaluationException

prim_stack

public Value prim_stack(Value... args)
                 throws EvaluationException
stack() : Returns a new, empty stack.

Throws:
EvaluationException

prim_tan

public Value prim_tan(Value... args)
               throws EvaluationException
tan(n) : Returns the tangent of n, with n in radians.

Throws:
EvaluationException

prim_test

public Value prim_test(Value... args)
                throws EvaluationException
test() : General-purpose testing primitive for the feature du jour.

Throws:
EvaluationException