|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.fun4j.Template
public class Template
This Class is the central facade to fun4j. It provides access to most components that fun4j users will use in their code.
| Field Summary | |
|---|---|
static Template |
fun4j
by using a static import this instance can be made available in user code. |
Function |
identity
the identity Function identity(x) = x |
| Constructor Summary | |
|---|---|
Template()
|
|
| Method Summary | ||
|---|---|---|
|
$(java.lang.Class<T> outerInterface,
java.lang.String methodBody)
|
|
java.util.Collection |
asCollection(Cons cons)
This utility method converts a Lisp list (i.e. a Cons object) into a Collection. |
|
|
asCollection(E... elements)
this utility method creates a Collection from a comma separated list of elements |
|
|
asCons(java.util.Collection<E> col)
this utility method converts a Collection into a Lisp list (i.e. a Cons object) |
|
Function |
bind(Function fun,
java.lang.Object... args)
binds parameters to the variables of a function. |
|
Function |
compile(Expression exp,
java.lang.String name)
compiles an AST Expression into an executable Java Function. |
|
Function |
compile(java.lang.String lispTerm)
compiles a LISP term into an executable Java Function. |
|
Function |
compose(Function... functions)
composes a set of functions functions[1..n] to a new function
functions[1] o functions[2] o ... functions[n] |
|
Function |
compose(Function f,
Function g)
composes two functions f(x) and g(x) to f(g(x)). |
|
Function |
constant(java.lang.Object obj)
produces a Function that returns a constant value. |
|
void |
define(java.lang.String name,
java.lang.Object value)
binds name to value in the global Lisp environment |
|
java.lang.Object |
eval(java.lang.String lispTerm,
java.lang.Object... args)
evaluates a LISP term. |
|
|
exists(Function predicate,
java.util.Collection<E> collection)
if the Function predicate evaluates to true for any element of the input collection true is returned, else false |
|
|
filter(Function predicate,
java.util.Collection<E> collection)
all elements of the input collection that match the predicate are collected into a new Collection. |
|
static Function |
fn(java.lang.String lambdaTerm)
by using a static import on this method you can define Lisp functions in user code as shown in the following example: import static org.fun4j.Template.fn; Function add = fn("(lambda (x y) (+ x y))"); |
|
|
foldleft(Function fun,
F acc,
java.util.Collection<E> col)
performs a foldleft operation of Function fun over the Collection col. |
|
|
foldleft(Function fun,
F acc,
java.util.Iterator<E> iter)
performs a foldleft operation of Function fun over Iterator iter. |
|
|
foldright(Function fun,
F acc,
java.util.Collection<E> col)
performs a foldright of Function fun over a Collection. |
|
|
foldright(Function fun,
F acc,
java.util.Iterator<E> iter)
performs a foldright of Function fun over Iterator iter. |
|
|
forAll(Function predicate,
java.util.Collection<E> collection)
if the Function predicate evaluates to true for all elements in the input collection, true is returned, else false. |
|
|
map(Function fun,
java.util.Collection<E> col)
applies the Function fun to each element of the Collection col. |
|
|
map(Function fun,
java.util.Iterator<E> iter)
applies the Function fun to each element of the Iterator iter. |
|
java.lang.Object |
parse(java.lang.String lispTerm)
parses a Lisp term input into its AST representation. |
|
Expression |
precompile(java.lang.String lispTerm)
precompiles a LISP term into an AST Expression. |
|
void |
runFile(java.lang.String filename)
evaluates all lisp expression in a file. |
|
boolean |
setTracing(boolean value)
if set to true tracing of Lisp function calls is traced. |
|
boolean |
setUseBigInts(boolean newValue)
if set to true (the default value) the Parser and Compiler will work with BigIntegers. |
|
boolean |
setWriteFile(boolean newValue)
if set to true the Compiler will write precompiled expression into tmp/*.lsp files, compiled bytecote into tmp/*.class files and debugging information is generated into the bytecode. |
|
Function |
toFunction(java.lang.reflect.Method method)
|
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static Template fun4j
public Function identity
| Constructor Detail |
|---|
public Template()
| Method Detail |
|---|
public static Function fn(java.lang.String lambdaTerm)
throws CompilationException
import static org.fun4j.Template.fn;
Function add = fn("(lambda (x y) (+ x y))");
lambdaTerm - the lambdaTerm defining the function.
Function.apply(Object...).
CompilationExceptionpublic java.lang.Object parse(java.lang.String lispTerm)
lispTerm -
public Function compile(Expression exp,
java.lang.String name)
throws CompilationException
Expression into an executable Java Function.
exp - the Expression to compilename - the Name of this expression, will be used for creation of the internal Class-Name
CompilationException
public Function compile(java.lang.String lispTerm)
throws CompilationException
Function.
lispTerm - the LISP term to be compiled
CompilationException
public Expression precompile(java.lang.String lispTerm)
throws CompilationException
Expression. This expression can be compiled to executable Java code
by calling compile(Expression, String)
lispTerm - the LISP term to be precompiled
Expression representing the LISP term
CompilationException
public Function bind(Function fun,
java.lang.Object... args)
PartialApplication containing function and arguments.
fun - the functionargs - the parameter to be bound to the function
PartialApplication containing function and arguments.
public java.lang.Object eval(java.lang.String lispTerm,
java.lang.Object... args)
throws CompilationException
lispTerm - the term to evaluateargs - optional parameters are passed in as function arguments
CompilationExceptionpublic void runFile(java.lang.String filename)
filename - the file to execute.
public void define(java.lang.String name,
java.lang.Object value)
name - the name to be usedvalue - the value to be associated with the name.public boolean setTracing(boolean value)
value - the new value
public boolean setUseBigInts(boolean newValue)
newValue - the new value
public boolean setWriteFile(boolean newValue)
newValue - the new value
public <E> java.util.Collection<E> asCollection(E... elements)
elements - Comma separated list of elements
public java.util.Collection asCollection(Cons cons)
cons - the Lisp list
public <E> Cons asCons(java.util.Collection<E> col)
E - the element type of the Collectioncol - the collection
public <E,F> java.util.Collection<F> map(Function fun,
java.util.Collection<E> col)
E - element type of input CollectionF - element type of output Collectionfun - the Function to be applied to all elements of Collection colcol - the collection to be mapped
public <E,F> java.util.Collection<F> map(Function fun,
java.util.Iterator<E> iter)
E - the element type of the input IteratorF - the element type of the output Collectionfun - the Function to be applied to each element of the Iteratoriter - the input Iterator
public <E> boolean exists(Function predicate,
java.util.Collection<E> collection)
E - the element Type of the input Collectionpredicate - the predicate Functioncollection - the input Collection
public <E> boolean forAll(Function predicate,
java.util.Collection<E> collection)
E - the element type of the input collectionpredicate - the predicate Functioncollection - the input Collection
public <E> java.util.Collection<E> filter(Function predicate,
java.util.Collection<E> collection)
E - the element type of the input collectionpredicate - the predicate Functioncollection - the input Collection
public <E,F> F foldright(Function fun,
F acc,
java.util.Iterator<E> iter)
E - The element type of the IteratorF - the result typefun - the accumulating functionacc - the accumulatoriter - the input Iterator
public <E,F> F foldright(Function fun,
F acc,
java.util.Collection<E> col)
E - the element type of the input collectionF - the result typefun - the accumulating functionacc - the accumulator that stores the resultscol - the input Collection
public <E,F> F foldleft(Function fun,
F acc,
java.util.Iterator<E> iter)
E - the element type of the input IteratorF - the result typefun - the accumulating Functionacc - the accumulatoriter - the input operator
public <E,F> F foldleft(Function fun,
F acc,
java.util.Collection<E> col)
E - the element type of the input CollectionF - the result typefun - the accumulating functionacc - the accumulatorcol - the input collection
public Function compose(Function f,
Function g)
f - a Funxtion f(x)g - a Function g(x)
public Function compose(Function... functions)
functions[1..n] to a new function
functions[1] o functions[2] o ... functions[n]
functions - the set of functions functions[1..n]
functions[1] o functions[2] o ... functions[n]public Function constant(java.lang.Object obj)
obj - the value to be returned by the constant function.
public <T> T $(java.lang.Class<T> outerInterface,
java.lang.String methodBody)
public Function toFunction(java.lang.reflect.Method method)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||