Jaskell API documentation | |
---|---|
cast
| to cast an object to a target type using the default jaskell conversion. |
implements
| to implement a Java interface with a jaskell tuple or function. |
import
| to load a class dynamically and use this class as a tuple. |
instanceof
| to find out if an object is an instance of a type. |
is
| to test if the two objects are the same object. |
jaskell
| the tuple containing all jaskell predefined functions. |
jaskell.bean
| the tuple with all Java Bean related functions. |
jaskell.bean.getProperty
| to get the property value of a bean. |
jaskell.bean.getPropertyType
| to find the type of a property for a Java Bean. |
jaskell.bean.setProperty
| to set the value of a property. |
jaskell.callcc
| call a function with the current continuation. |
jaskell.cast
| functions to convert object between different types. |
jaskell.cast.cast
| to cast an object to a target type using the default jaskell conversion. |
jaskell.cast.parse_int
| to parse a string to BigInteger. |
jaskell.cast.parse_num
| to convert a String to a BigDecimal. |
jaskell.cast.to_int
| to convert a BigDecimal to a BigInteger. |
jaskell.cast.to_num
| to convert a BigInteger to a BigDecimal. |
jaskell.cast.to_str
| to convert an object to a string. |
jaskell.classloader
| to create a ClassLoader object. |
jaskell.const
| to create a function that always return the same value regardless of the parameter. |
jaskell.date
| alias to dates |
jaskell.dates
| functions related to date/time operation. |
jaskell.dates.add
| to create a new Date object by adding some amount to a certain field of the Date object. |
jaskell.dates.date
| to convert a String to a java.util.Date object. |
jaskell.dates.dateformat
| to create a java.text.DateFormat object. |
jaskell.dates.datepart
| to get any field of a date object. |
jaskell.dates.day
| to get the day of month of a date. 1st day is 0. |
jaskell.dates.format
| to convert a Date object to a string of desired format. |
jaskell.dates.hour
| to get the hour of day of a date. |
jaskell.dates.millisecond
| to get the millisecond of second of a date. |
jaskell.dates.minute
| to get the minute of hour of a date. |
jaskell.dates.month
| to get the month of a date. January is 0. |
jaskell.dates.parse
| to convert a String to a java.util.Date object. |
jaskell.dates.second
| to get the second of minute of a date. |
jaskell.dates.weekday
| to get the day of week of a date. Sunday is 1 and Monday is 2. |
jaskell.dates.year
| to get the year of a date. |
jaskell.define
| to evaluate an expression with dynamic scope. |
jaskell.dynamic
| the tuple containing functions to dynamically evaluate jaskell code. |
jaskell.dynamic.eval
| to evaluate a piece of jaskell code dynamically. |
jaskell.exception
| The tuple with all exception related functions. Functions in this tuple are not quite intuitive to use. It is recommended to use helper functions under "jaskell.prelude" instead. |
jaskell.exception.catch
| to catch an exception. |
jaskell.exception.finally
| to ensure that the "finalize_block" will be evaluated after try_block even when try_block results in an exception. |
jaskell.exception.throw
| to throw an exception. |
jaskell.exception.try
| to monitor exceptions thrown out of the block. |
jaskell.exception.within
| to recover the uncaught exceptions |
jaskell.flip
| to flip the position of the two parameters of a function. |
jaskell.id
| the parameter is returned directly as return value |
jaskell.imperative
| functions to do imperative style programming. |
jaskell.imperative.for
| equivalent to for-loop in Java. |
jaskell.imperative.foreach
| to execute a callback function for each element of a container. |
jaskell.imperative.get
| to get the current value of a refernece. |
jaskell.imperative.ref
| to create and initialize a mutable reference. |
jaskell.imperative.set
| to set the current value of a reference. |
jaskell.import
| to import a jaskell expression from a jaskell source file. |
jaskell.io
| io related functions. |
jaskell.io.err
| the standard error |
jaskell.io.err.flush
| to flush the output. |
jaskell.io.err.print
| to print a string. |
jaskell.io.err.println
| to print a string and start a new line. |
jaskell.io.out
| the standard output |
jaskell.io.out.flush
| to flush the output. |
jaskell.io.out.print
| to print a string. |
jaskell.io.out.println
| to print a string and start a new line. |
jaskell.java
| the tuple with java related functions. |
jaskell.java.array
| to get the array type of a certain component type. |
jaskell.java.asTuple
| to convert any Java object to a tuple. |
jaskell.java.getClass
| to get the type of an object. |
jaskell.java.implements
| to implement a Java interface with a jaskell tuple or function. |
jaskell.java.import
| to load a class dynamically and use this class as a tuple. |
jaskell.java.instanceof
| to find out if an object is an instance of a type. |
jaskell.java.is
| to test if the two objects are the same object. |
jaskell.java.loadClass
| to load a class by name. |
jaskell.java.synchronized
| put a synchronized lock on an object and then evaluate an expression. |
jaskell.java.the_method
| to get the only method from a type |
jaskell.java.toTuple
| to convert a Class/Map to a tuple. |
jaskell.list
| list utility functions |
jaskell.list.fromArray
| to convert an array to a list. |
jaskell.list.head
| to get the 1st element of a list. |
jaskell.list.nil
| same as "[]" |
jaskell.list.revArray
| to convert a list to an array in reverse order. |
jaskell.list.tail
| to get the sublist after the 1st element. |
jaskell.list.toArray
| to convert a list to an array. |
jaskell.number
| functions related to number operator. |
jaskell.number.format
| to convert a Number object to a string of desired format. |
jaskell.number.numberformat
| to create a java.text.NumberFormat object. |
jaskell.number.parse
| to convert a String to a Number object. |
jaskell.operator
| functions corresponding to the operators. |
jaskell.operator.and
| the (&&) or 'and' operator. |
jaskell.operator.apply
| the ($) operator. |
jaskell.operator.at
| the (@) operator. |
jaskell.operator.cat
| the (++) operator. |
jaskell.operator.compose
| the (<<) operator. |
jaskell.operator.cons
| the (:) operator. |
jaskell.operator.div
| the (/) operator. |
jaskell.operator.eq
| the (==) operator. |
jaskell.operator.ge
| the (>=) operator. |
jaskell.operator.gt
| the (>) operator. |
jaskell.operator.le
| the (<=) operator. |
jaskell.operator.lt
| the (<) operator. |
jaskell.operator.minus
| the (-) operator. |
jaskell.operator.mod
| the (%) operator. |
jaskell.operator.mul
| the (*) operator. |
jaskell.operator.ne
| the (!=) operator. |
jaskell.operator.negate
| the (~) operator. |
jaskell.operator.or
| the (||) or 'or' operator. |
jaskell.operator.plus
| the (+) operator. |
jaskell.operator.seq
| the (>>) operator. |
jaskell.prelude
| the standard library loaded by 'importPrelude'. |
jaskell.prelude.assert
| assert that two objects are equal.jfun.jaskell. AssertionFailedException is thrown otherwise. |
jaskell.prelude.assertNe
| assert that two objects are not equal. jfun.jaskell.AssertionFailedException is thrown otherwise. |
jaskell.prelude.assertTrue
| assert that an object satisfies a predicate. jfun.jaskell.AssertionFailedException is thrown otherwise. |
jaskell.prelude.assoc
| to create a tuple using keys and values stored in a list. |
jaskell.prelude.assoc2
| to create a tuple using keys and values stored in two lists respectively. |
jaskell.prelude.auto
| to ensure that an expression is evaluated after another. |
jaskell.prelude.call
| a shortcut of jaskell.callcc |
jaskell.prelude.cast
| to cast an object to a target type using the default jaskell conversion. |
jaskell.prelude.const
| to create a function that always return the same value regardless of the parameter. |
jaskell.prelude.curry
| to convert a function expecting a list object of size n to a new function expecting n parameters. |
jaskell.prelude.decimal
| to create a BigDecimal value |
jaskell.prelude.default
| to specify default values for parameters. |
jaskell.prelude.define
| to evaluate an expression with dynamic scope. |
jaskell.prelude.do
| the monad "do" notation. |
jaskell.prelude.each
| iterate through a list/array using an imperative loop syntax |
jaskell.prelude.error
| to throw an exception to report an error message. |
jaskell.prelude.eval
| to evaluate a piece of jaskell code dynamically. |
jaskell.prelude.filter
| To create a sub-list by filtering out elements that doesn't satisfy a predicate. |
jaskell.prelude.find
| To find the ordinal position of an element in a list. -1 is returned if the element cannot be found in the list. |
jaskell.prelude.flip
| to flip the position of the two parameters of a function. |
jaskell.prelude.fold
| folds a list to a value by repeatedly applying a function to the elements. |
jaskell.prelude.fold2
| folds a tuple/Map to a value by repeatedly applying a function to the key/value pairs. |
jaskell.prelude.foldn
| folds a collection that's iterable to a value by repeatedly applying a function to the loop variables in each iteration. |
jaskell.prelude.foreach
| to execute a callback function for each element of a container. |
jaskell.prelude.id
| the parameter is returned directly as return value |
jaskell.prelude.in
| to determine if an element is contained in a list. |
jaskell.prelude.integer
| to create a BigInteger object |
jaskell.prelude.iterate
| to transform a function to use an imperative loop syntax |
jaskell.prelude.list
| to create a list with elements in the range of [from,to]. |
jaskell.prelude.lookup
| To find the ordinal position of the first element in a list that satisfies the given predicate. -1 is returned if the element cannot be found in the list. |
jaskell.prelude.map
| to transform a list/map/tuple by applying a function to each element in the container. |
jaskell.prelude.new
| java style "new" operator |
jaskell.prelude.overload
| to provide different expressions based on the types of a few variables. |
jaskell.prelude.print
| to print a string. |
jaskell.prelude.println
| to print a string and start a new line. |
jaskell.prelude.promote
| to create a function that always returns the same value after receiving n parameters. |
jaskell.prelude.puts
| to use the key-value pairs stored in a list to functionally update a tuple. |
jaskell.prelude.puts2
| to use the key-value pairs seperately stored in two lists to functionally update a tuple. |
jaskell.prelude.ref
| to create a mutable reference of a value. |
jaskell.prelude.replicate
| To create a list by replicating an object for n times. |
jaskell.prelude.revAppend
| to append elements in a list in reverse order to another list. |
jaskell.prelude.reverse
| to reverse the order of elements in a list. |
jaskell.prelude.sum
| to get the sum of all elements in a list. |
jaskell.prelude.switch
| the switch-case idiom. |
jaskell.prelude.throw
| to throw an exception. |
jaskell.prelude.try
| the try-catch-finally with a more intuitive syntax. |
jaskell.prelude.try_catch_finally
| a more generalized try-catch-finally idiom. |
jaskell.prelude.typecase
| the type-case idiom. |
jaskell.prelude.uncurry
| to convert a function expecting n parameters to a new function expecting a list object of size n. |
jaskell.prelude.value
| to make sure an object is not a function. |
jaskell.prelude.when
| a generalized form of 'switch'. |
jaskell.prelude.with
| to evaluate an expression with all members of an object in scope |
jaskell.text
| string manipulation functions. |
jaskell.text.split
| to split a string into an array |
jaskell.tuple
| contains functions to manipulate tuples. |
jaskell.tuple.at
| to get an element identified by a key |
jaskell.tuple.containsKey
| to test if a key is present in an associative array |
jaskell.tuple.extends
| to "extend" tuple t2 with tuple t1. |
jaskell.tuple.includes
| to create a tuple that includes members from both t1 and t2. |
jaskell.tuple.keys
| to get the member keys of a tuple. |
jaskell.tuple.keys_array
| to get the member keys of a tuple. |
jaskell.tuple.put
| dynamically extend/override a tuple member. |
jaskell.tuple.remove
| to create a new tuple by removing one member. |
jaskell.tuple.removes
| create a tuple by removing a list of members |
jaskell.tuple.sizeof
| to get the size of a container |
jaskell.tuple.subtuple
| dynamically create a sub-tuple. |
jaskell.util
| general utility functions. |
jaskell.util.properties
| to read a property file as a tuple. |
jaskell.version
| to get the current version of jaskell. |
jaskell.with
| to evaluate an expression with all members of an object in scope |
java
| the java classes whose package names start with "java." and pre-loaded by 'importStandardClasses'. |
javax
| the java classes whose package names start with "javax." and pre-loaded by 'importStandardClasses'. |
junit
| the junit assertion functions. Only available in a JUnit integrated runtime. |
junit.assertEquals
| to assert that two objects are equal |
junit.assertError
| to assert that an expression throws a certain exception. |
junit.assertInstanceof
| To assert that an object is an instance of a type. |
junit.assertNotEquals
| to assert that two objects are not equal |
junit.assertNotNull
| to assert that an object is not null. |
junit.assertNotSame
| to assert that two objects are not same |
junit.assertNull
| to assert that an object is null. |
junit.assertSame
| to assert that two objects' identity are same |
junit.assertTrue
| to assert that an object is true. |
junit.fail
| to report failure. |
not
| equivalent to the '!' operator |
now
| to get the current time. |
null
| the null value |
synchronized
| put a synchronized lock on an object and then evaluate an expression. |
API Detail |
---|
Object cast(Class target_type, Object obj)
This function has 2 overloaded versions:
Object implements(Tuple tuple, Class interface_type)
Object implements(Function function, Class interface_type)
This function has two different overloaded versions:
When using a function to implement an interface, the interface should have only one method, The function is then adapted to an object that implements this interface.
When using a tuple to implement an interface, the tuple should have members with the same name declared in the interface. The tuple is then adapted to an object that implements this interface.
This function has 2 overloaded versions:
Tuple import(String classname)
Tuple import(Tuple options)
This function has several different overloaded versions:
When the parameter is a string, it simply calls Class.forName(), and then transforms the Class object to a tuple.
When the parameter is a tuple and the tuple contains only a member named "classname", it calls Class.forName() and tranforms the Class object to a tuple.
When the parameter is a tuple with a member named "classloader", it will use the ClassLoader object specified in that member to load the class.
The returned tuple can be used as if it were the class. For example:
import "java.lang.Integer".parseInt["10"]
boolean instanceof(Object obj, Class type)
"obj `instanceof Integer" is equivalent to "obj instanceof Integer" in Java.
boolean is(Object a, Object b)
"is(a,b)" is equivalent to "a==b" in Java.
Object getProperty(Object obj, String key)
Class getPropertyType(Class beanType, String key)
void setProperty(Object obj, String key, Object val)
Object callcc((Object->Object)->Object f)
callcc can be used to exit from a loop or nested function calls.
For example:
search l target = let pos = ref 0; next r = set(r, get r+1); callcc \return -> foreach(l, \i->if i==target then return(get pos) else next pos) end
The above "search" function searches a list/array to find the position of an element. When an element is found, it exits the foreach function by calling the "return" function, which is the "continuation" at the point of "callcc".
The callcc function is only a restricted continuation.
The continuation is only valid within the static scope of the callcc function.
Unlike continuation in Scheme, it cannot be saved in a refernece and
used outside of the static scope of the callcc function.
This means, this is an escape-only continuation mechanism.
Object cast(Class target_type, Object obj)
BigInteger parse_int(String str)
NumberFormatException if the string is not in a valid format.
BigDecimal parse_num(String str)
BigInteger to_int(BigDecimal num)
Fractional part is discarded if any.
BigDecimal to_num(BigInteger i)
String to_str(Object obj)
null is converted to "null", non-null object is converted using the toString() method.
ClassLoader classloader(Tuple options)
The following items are valid in the "options" tuple:
parent
- the parent ClassLoader object.
If ommitted, or null, the ClassLoader used by the Jaskell object is used instead.
classpath
- the classpath used to locate classes and resources.
"classpath" can be a String, a File, a URL or a list of classpath.
When a string is specified for a classpath, "," or ";" can be used to separate
path elements.
A valid example is:
["lib/ant.jar, ../external_lib/xcercse.jar; /home/neptune/lib/neptune.jar", ["x.jar","build/y.jar"], ["z.jar"] ]
basedir
- the base directory used to translate relative path specified in classpath.
Optional parameter. Default value is the current directory. Can be either a File or a String.
policy
- the class loader policy to use.
Optional parameter. The following 4 options are currently supported:
parent-first
- to search parent class loader first.
This is the default class loader policy.
parent-only
- to only search the parent ClassLoader.
child-first
- to search child ClassLoader first.
Be careful with this option, it can cause mysterious type mismatch error.
child-only
- to ignore the parent ClassLoader.
Typically, the default "parent-first" is good enough.
Function const (Expression val)
The "val" expression is not evaluated until needed
Date add(int fld, int amount, Date date)
Parameters:
fld
- the Date field to add. Refer to java.util.Calendar for applicable fields.amount
- the amount to add to the field.date
- the date to add on.This function has 3 overloaded versions:
Date date(DateFormat df, String str)
Date date(Tuple options, String str)
Date date(java.util.Map options, String str)
The options parameter can contain the following items:
locale
- the locale to format the Date.timezone
- the time zone to format the Date.pattern
- the desired pattern string. such as "yyyy-MM-dd"lenient
- whether lenient parsing is enabled. Default is falseRefer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.
This function has 3 overloaded versions:
DateFormat dateformat(DateFormat df)
DateFormat dateformat(Tuple options)
DateFormat dateformat(java.util.Map options)
The options parameter can contain the following items:
locale
- the locale to format the Date.timezone
- the time zone to format the Date.pattern
- the desired pattern string. such as "yyyy-MM-dd"lenient
- whether lenient parsing is enabled. Default is falseRefer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.
int datepart(int fld, Date date)
The field values are defined in java.util.Calendar.
int day(Date date)
This function has 3 overloaded versions:
String format(DateFormat df, Date date)
String format(Tuple options, Date date)
String format(java.util.Map options, Date date)
The options parameter can contain the following items:
locale
- the locale to format the Date.timezone
- the time zone to format the Date.pattern
- the desired pattern string. such as "yyyy-MM-dd"Refer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.
int hour(Date date)
int millisecond(Date date)
int minute(Date date)
int month(Date date)
This function has 3 overloaded versions:
Date parse(DateFormat df, String str)
Date parse(Tuple options, String str)
Date parse(java.util.Map options, String str)
The options parameter can contain the following items:
locale
- the locale to format the Date.timezone
- the time zone to format the Date.pattern
- the desired pattern string. such as "yyyy-MM-dd"lenient
- whether lenient parsing is enabled. Default is falseRefer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.
int second(Date date)
int weekday(Date date)
int year(Date date)
This function has 2 overloaded versions:
Object define(Tuple scope, Expression expr)
Object define(java.util.Map scope, Expression expr)
The free occurrences of variables in "expr" will be first resoled by the variables defined in the dynamic scope.
"define {a=1,b=2} (a+b)" evaluates to 3.
This function has 2 overloaded versions:
Object eval(Tuple env, String module_name, CharSequence source)
Object eval(java.util.Map env, String module_name, CharSequence source)
Parameter Descriptions:
This function has 4 overloaded versions:
Object catch(Expression expression, Class exception_type, (Throwable->Object) handler)
Object catch(Expression expression, String exception_type_name, (Throwable->Object) handler)
Object catch(Expression expression, Class exception_type, Expression handler)
Object catch(Expression expression, String exception_type_name, Expression handler)
When a String is passed in for the exception_type, it is automatically converted to a Class object that represents the type of the exception.
The exception handler can be either a Function or a regular Expression.
When the handler is a function, the exception object is passed in to this function; otherwise, the expression is simply evaluated disregarding the exception object.
Object finally(Expression try_block, Expression finalize_block)
void throw(Throwable e)
try(some_expression)
will monitor the exception that might be thrown from evaluating some_expression.
Object within(Expression tried_block)
When the "try" function is called, exceptions thrown out of the tried expression are monitored; "within" function dismisses the "monitor" of the exception.
This is a sample usage of within-try-catch:
within $ try (some_expression) `(catch "java.lang.RuntimeException") (\e->jaskell.io.out.println(e.getMessage[]))
(b->a->c) flip ((a->b->c) f)
"flip (-) 1 2" is equivalent to "2 - 1".
Object id(Object val)
void for(Object init_variable, (Object->boolean) condition,
(Object->Object) increment, (Object->Object) loop_body)
Parameters:
init_variable
- the initial value for the loop variable.condition
- the function called before each iteration
to determine based on the current value of the loop variable
whether the loop should continue.increment
- the function called after each iteration
to get the next value of the loop variable.loop_body
- the loop body. Called in each iteration with
the current value of the loop variable as parameter."for init (\v->cond v) (\v->inc v) (\v->body)" is equivalent to "for(v=init;cond v;v=inc v){body;}"
This function has 10 overloaded versions:
void foreach(int i, (int->Object) f)
The loop variable is passed to function f in each iteration.
If i>0, then the loop variable starts from 0 to (i-1). If i<0, then the loop variable starts from 0 to (i+1).
void foreach(CharSequence str, (char->Object) f)
In each iteration, the character is passed in to the function f.
void foreach(Object arr, (Object->Object) f)
In each iteration, the array element is passed in to the function f.
void foreach(jfun.util.List list, (Object->Object) f)
In each iteration, the list element is passed in to the function f.
void foreach(java.util.List list, (Object->Object) f)
In each iteration, the list element is passed in to the function f.
void foreach(jfun.util.dict.Dict dict, (Object->Object->Object) f)
In each iteration, the key and the value are passed into the function f as in "f(key, value)".
The order of the key-value pair is not defined.
void foreach(java.util.Map map, (Object->Object->Object) f)
In each iteration, the key and the value are passed into the function f.
as in "f(key, value)".
void foreach(java.util.Iterator it, (Object->Object) f)
After the foreach function, it.hasNext()==false
void foreach(java.util.Enumeration en, (Object->Object) f)
After the foreach function, en.hasMoreElements()==false
void foreach(Tuple tuple, (Object->Object->Object) f)
In each iteration, a member key and the value of the member are passed in to the function f as "f key value".
The tuple member is not evaluated before passed into the function. It is up to the function to decide whether to evaluate this value.
The order of the members is not defined.
"ref 1" will create a refernece whose initial value is 1.
"set r 2" will change the value that r references to 2.
This function has 2 overloaded versions:
Object import(Tuple options)
Object import(java.util.Map options)
The options tuple can contain the following members:
env
- the extra variable definitions to resolve unresolved variables in the imported code.
Jaskell is a statically scoped language, but the "import" function provides a limited support for dynamic scoping.
This member is optional.
file
- the file to be imported.resource
- the name of the resource that's gonna be loaded from a ClassLoader.refresh
- whether to force a refresh if the file or resource is already loaded. Default value is false.classloader
- the ClassLoader used to load resource and load classes in the imported code.
If omitted, the current ClassLoader used by the Jaskell object is used.
void flush()
void print(Object msg)
void println(Object msg)
void flush()
void print(Object msg)
void println(Object msg)
Class array(Class component_type)
"array(int.class) is equivalent to "int[].class" in Java.
This function has 2 overloaded versions:
Tuple asTuple(Tuple t)
This returns the tuple itself directly.
Tuple asTuple(Object obj)
This Converts the object to a tuple.
It is typically not necessary to use this function. Jaskell can convert a Java object to a tuple implicitly when any member variable or method is invoked against this object.
For example:
java.lang.StringBuffer.new[].getLength[]
However, for some functions that only expect Tuple as parameter,
For example, the following code will fail because a non-tuple
object is used where a tuple is expected:
"abc" `(jaskell.tuple.includes) "bcd"
In this senario, 'asTuple' function can be used to incur the conversion explicitly.
Class getClass(Object obj)
"getClass(obj)" is equivalent to "obj.getClass()" in Java. The Object.getClass() method is disabled in jaskell for security reason. getClass(null) returns null.
This function has 2 overloaded versions:
Object implements(Tuple tuple, Class interface_type)
Object implements(Function function, Class interface_type)
This function has two different overloaded versions:
When using a function to implement an interface, the interface should have only one method, The function is then adapted to an object that implements this interface.
When using a tuple to implement an interface, the tuple should have members with the same name declared in the interface. The tuple is then adapted to an object that implements this interface.
This function has 2 overloaded versions:
Tuple import(String classname)
Tuple import(Tuple options)
This function has several different overloaded versions:
When the parameter is a string, it simply calls Class.forName(), and then transforms the Class object to a tuple.
When the parameter is a tuple and the tuple contains only a member named "classname", it calls Class.forName() and tranforms the Class object to a tuple.
When the parameter is a tuple with a member named "classloader", it will use the ClassLoader object specified in that member to load the class.
The returned tuple can be used as if it were the class. For example:
import "java.lang.Integer".parseInt["10"]
boolean instanceof(Object obj, Class type)
"obj `instanceof Integer" is equivalent to "obj instanceof Integer" in Java.
boolean is(Object a, Object b)
"is(a,b)" is equivalent to "a==b" in Java.
Class loadClass(String classname)
Same as Class.forName
Object synchronized(Object some_obj, Expression expr)
"synchronized(obj, some_expr)" is equivalent to:
synchronized(obj){ return some_expr; }
in Java.
Method the_method(Class type)
a Java interface can be implemented by a jaskell function. if the interface has only one method. this function gets this method object from such Java type. null is returned if this type is not such type.
This function has 3 overloaded versions:
Tuple toTuple(Tuple t)
This returns the tuple itself.
Tuple toTuple(Class type)
This converts the Class object to a Tuple so that static members of the class can be referenced with this tuple.
Tuple toTuple(java.util.Map map)
This converts a java.util.Map object to a Tuple. "toTuple m.key" is equivalent to "m.get("key")" in Java.
List fromArray(Object[] arr)
Object head(List list)
Object[] revArray(List list)
List tail(List list)
Object[] toArray(List list)
This function has 3 overloaded versions:
String format(NumberFormat nf, Number num)
String format(Tuple options, Number num)
String format(java.util.Map options, Number num)
The options parameter can contain the following items:
locale
- the locale to format the number.pattern
- the desired pattern string.Refer to jfun.jaskell.optionbeans.MakeNumberFormat for the Java Bean class corresponding to the signature.
This function has 3 overloaded versions:
NumberFormat numberformat(NumberFormat df)
NumberFormat numberformat(Tuple options)
NumberFormat numberformat(java.util.Map options)
The options parameter can contain the following items:
locale
- the locale to format the number.pattern
- the desired pattern string.Refer to jfun.jaskell.optionbeans.MakeNumberFormat for the Java Bean class corresponding to the signature.
This function has 3 overloaded versions:
Number parse(NumberFormat nf, String str)
Number parse(Tuple options, String str)
Number parse(java.util.Map options, String str)
The options parameter can contain the following items:
locale
- the locale to format the number.pattern
- the desired pattern string.Refer to jfun.jaskell.optionbeans.MakeNumberFormat for the Java Bean class corresponding to the signature.
Object assert(Object target, Object obj)
Object assertNe(Object target, Object obj)
Object assertTrue((Object->boolean) predicate, (Object->String) messager, Object obj)
Tuple assoc(List key_vals)
The following code:
assoc ["name", "tom", "age", 10]
is equivalent to
{name="tom", age=10}
Tuple assoc2(List keys, List vals)
The following code:
assoc2 ["name", "age"] ["tom", 10]
is equivalent to
{name="tom",age=10}
"auto expr1 expr2" will evaluate expr1 after expr2 even if expr2 throws an exception.
This is similar to the 'finally' function, except that the order of the two parameters are flipped.
his function is handy when 'expr2' is a long complex expression, where we can say:
auto expr1 $ ... //expr2
Object call(Expression expr)
the expression called can use the return function to exit from the middle.
The following code using call:
call(return 1)
is equivalent to the following code using callcc:
callcc \return->return 1
Object cast(Class target_type, Object obj)
Function const (Expression val)
The "val" expression is not evaluated until needed
The folllowing assertion succeeds:
assert(6, plus3 1 2 3) where plus3 = curry 3 sum; end
BigDecimal decimal(Object v)
Either String or Number can be passed in to this function to create a BigDecimal object
'default' function takes advantage of the dynamic scoping support of Jaskell to provide a default-parameter support
For example:
add args = default args {a=1,b=2,c=3} $ 1+2+3;
The above "add" function adds up three numbers. These named parameters are passed into the function in a tuple and are given default values by the 'default' function.
Then, when calling:
add {a=10,b=0}
The "c" is not provided in the argument tuple but instead is given the default value "3". Thus, the evaluation result is 13.
This function has 2 overloaded versions:
Object define(Tuple scope, Expression expr)
Object define(java.util.Map scope, Expression expr)
The free occurrences of variables in "expr" will be first resoled by the variables defined in the dynamic scope.
"define {a=1,b=2} (a+b)" evaluates to 3.
Function do(Function bind)
The parameter is the monad "bind" function.
The return value is a function that supports "do-notation" for the given "bind" operation.
The monad "do-notation" has the following characteristic: "do {x=a} b" is equivalent to "a `bind \x->b".
"foreach [1,2,3] \i->f i" is equivalent to "each {i=[1,2,3]} $ f i"
void error(String msg)
List((Object-boolean) predicate, List)
The folllowing assertion succeeds:
assert([1,2], filter (3.>) [1,2,3])
int (Object target, List list)
The folllowing assertion succeeds:
assert(1, find 2 [1,2,3])
(b->a->c) flip ((a->b->c) f)
"flip (-) 1 2" is equivalent to "2 - 1".
seed_type fold((seed_type->elem_type->seed_type) f, seed_type seed, [elem_type] list)
seed_type fold((seed_type->key_type->val_type->seed_type) f, seed_type seed, {key_type=val_type} t)
seed_type fold(int n, (seed_type->...->seed_type) f, seed_type seed, iterable collection)
This number doesn't count the seed value. Therefore the folding function takes (n+1) parameters.
This function has 10 overloaded versions:
void foreach(int i, (int->Object) f)
The loop variable is passed to function f in each iteration.
If i>0, then the loop variable starts from 0 to (i-1). If i<0, then the loop variable starts from 0 to (i+1).
void foreach(CharSequence str, (char->Object) f)
In each iteration, the character is passed in to the function f.
void foreach(Object arr, (Object->Object) f)
In each iteration, the array element is passed in to the function f.
void foreach(jfun.util.List list, (Object->Object) f)
In each iteration, the list element is passed in to the function f.
void foreach(java.util.List list, (Object->Object) f)
In each iteration, the list element is passed in to the function f.
void foreach(jfun.util.dict.Dict dict, (Object->Object->Object) f)
In each iteration, the key and the value are passed into the function f as in "f(key, value)".
The order of the key-value pair is not defined.
void foreach(java.util.Map map, (Object->Object->Object) f)
In each iteration, the key and the value are passed into the function f.
as in "f(key, value)".
void foreach(java.util.Iterator it, (Object->Object) f)
After the foreach function, it.hasNext()==false
void foreach(java.util.Enumeration en, (Object->Object) f)
After the foreach function, en.hasMoreElements()==false
void foreach(Tuple tuple, (Object->Object->Object) f)
In each iteration, a member key and the value of the member are passed in to the function f as "f key value".
The tuple member is not evaluated before passed into the function. It is up to the function to decide whether to evaluate this value.
The order of the members is not defined.
Object id(Object val)
boolean in(Object element, List list)
BigInteger integer(Object v)
Either String or Number can be passed to this function to create a BigInteger object
"iterate foreach {i=[1,2,3]} $ f i" is equivalent to "foreach [1,2,3] \i->f i".
List list(int from, int to)
The folllowing assertion succeeds:
assert([1,2,3], list 1 3)
int lookup((Object->boolean) predicate, List list)
The folllowing assertion succeeds:
assert(1, lookup (1.<) [1,2,3])
This function has 3 overloaded versions:
List map((Object->Object) f, List list)
to transform a list by applying the function to each element
The folllowing assertion succeeds:
assert([2,4,6], map (2.*) [1,2,3])
Tuple map((Object->Object) f, Tuple tuple)
to transform a tuple by applying the function to each member value
The folllowing assertion succeeds:
assert({a=2,b=4}, map (2.*) {a=1,b=2})
Tuple map((Object->Object) f, java.util.Map m)
to transform a java.util.Map by applying the function to each entry value
Object new(Class clazz, Object[] arguments)
The folllowing assertion succeeds:
assert("string,int", getTypes "abc" 1) where getTypes a b = overload [a,b] .case [java.int, java.int] "int,int" .case [java.lang.String, java.int] "string,int" .end end
void print(Object msg)
void println(Object msg)
This is a generalization of the 'const' function.
The folllowing assertion succeeds:
assert("x", const3 "a" "b" "c") where const3 = promote 3 "x"; end
Tuple puts(Tuple t, List key_vals)
The folllowing assertion succeeds:
assert({zero=0;one=1;two=2}, puts {zero=0} ["one",1,"two",2])
Tuple puts(Tuple t, List keys, List vals)
The folllowing assertion succeeds:
assert({zero=0;one=1;two=2}, puts2 {zero=0} ["one","two"] [1,2])
Tuple ref(Object obj)
Different than 'jaskell.imperative.ref', this function provides more helper utilities.
Description
the returned tuple contains the following member functions:
deref
- to get the referenced value.get
- to get the referenced value.set
- to set the referenced value.inc
- to increment the referenced value by 1.dec
- to decrement the referenced value by 1.transform
- to change the referenced value with a function.
The current referenced value is passed in to the function and the return value is used to update the referenced value.
+, -, *, /, %, ~, @, #, ~, ==, !=,
<, >, <=, >=;
and, or, &&, ||, :, ++
- overloaded operators as long as the referenced value supports them.List replicate(int n, Object elem)
The folllowing assertion succeeds:
assert([1,1,1,1], replicate 4 1)
List revAppend(List append_to, List list)
The folllowing assertion succeeds:
assert([4,3,2,1], revAppend [4] [1,2,3])
List reverse(List list)
The folllowing assertion succeeds:
assert([3,2,1], reverse [1,2,3])
The folllowing assertion succeeds:
assert(10, sum[1,2,3,4])
The folllowing assertion succeeds:
assert("three", translate 3) where translate n = switch n .case 1 "one" .case 2 "two" .case 3 "three" .default "unknown" .end end
void throw(Throwable e)
A typical try-catch-finally can be written as:
try (some_expression) .catch(Exception1, handler1) .catch(Exception2, Handler2) .finally(have_to_run_expression) .end
Same as Java, try-catch, or try-finally is also allowed:
try(some_expression) .catch(Exception1, handler1) .end
try(some_expression) .finally(have_to_run_expression) .end
jaskell.prelude.try_catch_finally
a more generalized try-catch-finally idiom.
'try' only handles direct execution of expression that could throw exception.
Some higher-order construct (such as a function, or an interface, that when executed in a context, may throw exception) also needs the try-catch-finally idiom. This function provides this idiom to these higher-order constructs.
The 1st parameter should be a tuple with the following members:
try
- the function that does the "try" action.catch
- the function that does the "catch" action.finally
- the function that does the "finally" action.end
- the function that ends a try-catch-finally construct.The return value is a function that has the same form as "jaskell.prelude.try".
Equivalent to "when (jaskell.java.instanceof)"
The folllowing assertion succeeds:
assert("string", translate "a") where translate x = typecase x .case (java.int) "int" .case (java.lang.String) "string" .default "unknown" .end end
The folllowing assertion succeeds:
assert(3, add[1,2]) where add = uncurry 2 (+); end
Object value(Object obj)
The same object is returned if it is not a function; Exception is thrown otherwise.
This is particularly useful when we want to make sure enough parameters are provided to a function and partial-application is not in effect.
'switch' only tests equality for each case, while 'when' parameterizes this test condition.
The folllowing assertion succeeds:
assert("string", translate "a") where translate x = when (jaskell.java.instanceof) x .case (java.int) "int" .case (java.lang.String) "string" .default "unknown" .end end
Object with(Object obj, Expression expr)
This function resembles the "with" syntax available in Visual Basic, where by using "with", all methods of an object are made visible to the statements in the body of "with".
String[] split(String delim, String str)
This function has 7 overloaded versions:
Object at(Tuple t, Object key)
null is returned if the key is not present in the tuple.
char at(CharSequence str, int ind)
Object at(java.util.List list, int ind)
Object at(java.util.Map map, Object key)
Object at(jfun.util.List list, int ind)
ArrayIndexOutOfBoundsException is thrown when ind<0 or ind>=list.size()
Object at(Object arr, int ind)
ArrayIndexOutOfBoundsException is thrown when ind<0 or ind>=Array.getLength(arr)
Object at(jfun.util.dict.Map map, Object key)
This function has 3 overloaded versions:
boolean containsKey(java.util.Map map, Object key)
boolean containsKey(jfun.util.dict.Map map, Object key)
boolean containsKey(jfun.jaskell.Tuple t, Object key)
"containsKey t key" is similar to "at(t, key)==null" or "t@key==null" as they all report the presence of a key. containsKey is more straight-forward and simpler though.
More importantly, containsKey does not evaluate the member while "at" and "@" do evaluate the member if the container is a Tuple and the key exists.
Tuple extends(Tuple t1, Tuple t2)
"tuple1 `extends` tuple2" will create a new tuple whose members come from tuple1 and tuple2.
When there's name conflict between two members from tuple1 and tuple2, the one from tuple1 takes precedence.
"this" variable binds to the new tuple.
For example:
extended.fullname where tuple1 = {firstname="Tom",}; tuple2 = {firstname="Jack",lastname="Stone",fullname="${this.firstname} ${this.lastname}"}; extended = tuple1 `extends tuple2; end
The above expression should evaluate to "Tom Stone" because "this" is now bound to "extended", not "tuple1" any more.
'extends' does not evaluate any tuple member.
Tuple includes(Tuple t1, Tuple t2)
Different from 'extends', 'includes' doesn't change the "this" variable binding.
included.fullname where tuple1 = {firstname="Tom";}; tuple2 = {firstname="Jack";lastname="Stone";fullname="${this.firstname} ${this.lastname}"}; included = tuple1 `includes tuple2; end
The above expression will evaluate to "Jack Stone".
'includes' does not cause any tuple member to be evaluated.
List keys(Tuple t)
The keys are put into a list.
he order of the keys are not defined.
Object[] keys_array(Tuple t)
The keys are put into an array.
he order of the keys are not defined.
Tuple put(Tuple t, Object key, Expression val)
"put {} "name" "Tom"" is equivalent to "{name="Tom"}"
'put' is more flexible than a tuple literal because any string or even non-string objects can be used as the member key.
'put' does not evaluate the expression that's used as the member value.
Tuple remove(Tuple t, Object key)
Note, this is functional remove, the original Tuple is not changed.
This function has 3 overloaded versions:
Tuple removes(Tuple t, Object arr)
Tuple removes(Tuple t, java.util.List keys)
Tuple removes(Tuple t, jfun.util.List keys)
Note, this is functional update. The original Tuple is not changed.
This function has 4 overloaded versions:
int sizeof(CharSequence str)
int sizeof(Object array)
int sizeof(jfun.util.Sizeable sizeable)
int sizeof(java.util.Collection col)
This function has 2 overloaded versions:
Tuple subtuple(Tuple t, List keys)
Tuple subtuple(Tuple t, Object[] keys)
A list/array of the keys are taken and tuple members are picked from the tuple based on the keys to create a new tuple. If a certain key cannot be found in the tuple, it is silently ignored.
'this' variable still binds to the original tuple, not the subtuple.
Therefore, the following expression still evaluates to "Tom Stone" even if
the subtuple does not contain the "firstname" and "lastname" member any more.
subtuple( {firstname="Tom", lastname="Stone";fullname="${this.firstname} ${this.lastname}"}, ["fullname"] ).fullname
"subtuple(t, ["a","b"})" is equivalent to "t.{a,b}". subtuple function just provides more flexibility to handle non-string keys.
This function has 2 overloaded versions:
Tuple properties(Tuple options)
Tuple properties(java.util.Map options)
The following items can be specified in the "options" parameter:
file
- the path of the properties file.resource
- the resource name to load from a class loader.classloader
- the ClassLoader to load resource from.Refer to jfun.jaskell.optionbeans.LoadProperties for the Java Bean class corresponding to the signature.
If a property in the properties file is named as "a.b", the value is stored in the result tuple as "a.b", which means, the "b" is stored in subtuple named "a".
Object with(Object obj, Expression expr)
This function resembles the "with" syntax available in Visual Basic, where by using "with", all methods of an object are made visible to the statements in the body of "with".
Object assertEquals(Tuple options)
lists, arrays, tuples, maps are automatically coersed and compared by content.
The options tuple can contain the following members:
Object assertError(Tuple options)
The options tuple can contain the following members:
Object catch(Throwable err)
Object assertInstanceof(Tuple options)
The options tuple can contain the following members:
Object assertNotEquals(Tuple options)
lists, arrays, tuples, maps are automatically coersed and compared by content.
The options tuple can contain the following members:
Object assertNotNull(Tuple options)
The options tuple can contain the following members:
Object assertNotSame(Tuple options)
The options tuple can contain the following members:
Object assertNull(Tuple options)
The options tuple can contain the following members:
Object assertSame(Tuple options)
The options tuple can contain the following members:
Object assertTrue(Tuple options)
The options tuple can contain the following members:
void fail(String msg)
when null is passed as the "msg" parameter, the Assert.fail() method is invoked instead.
not true == false
Equivalent as "new Date()" in Java.
Same as "null" in Java.
Object synchronized(Object some_obj, Expression expr)
"synchronized(obj, some_expr)" is equivalent to:
synchronized(obj){ return some_expr; }
in Java.