Jaskell API documentation:

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

cast

to cast an object to a target type using the default jaskell conversion.

Object cast(Class target_type, Object obj)


implements

to implement a Java interface with a jaskell tuple or function.

This function has 2 overloaded versions:

This function has two different overloaded versions:


import

to load a class dynamically and use this class as a tuple.

This function has 2 overloaded versions:

This function has several different overloaded versions:

The returned tuple can be used as if it were the class. For example:

      import "java.lang.Integer".parseInt["10"]


instanceof

to find out if an object is an instance of a type.

boolean instanceof(Object obj, Class type)

"obj `instanceof Integer" is equivalent to "obj instanceof Integer" in Java.


is

to test if the two objects are the same object.

boolean is(Object a, Object b)

"is(a,b)" is equivalent to "a==b" in Java.


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.

Object getProperty(Object obj, String key)


jaskell.bean.getPropertyType

to find the type of a property for a Java Bean.

Class getPropertyType(Class beanType, String key)


jaskell.bean.setProperty

to set the value of a property.

void setProperty(Object obj, String key, Object val)


jaskell.callcc

call a function with the current continuation.

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.


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.

Object cast(Class target_type, Object obj)


jaskell.cast.parse_int

to parse a string to BigInteger.

BigInteger parse_int(String str)

NumberFormatException if the string is not in a valid format.


jaskell.cast.parse_num

to convert a String to a BigDecimal.

BigDecimal parse_num(String str)


jaskell.cast.to_int

to convert a BigDecimal to a BigInteger.

BigInteger to_int(BigDecimal num)

Fractional part is discarded if any.


jaskell.cast.to_num

to convert a BigInteger to a BigDecimal.

BigDecimal to_num(BigInteger i)


jaskell.cast.to_str

to convert an object to a string.

String to_str(Object obj)

null is converted to "null", non-null object is converted using the toString() method.


jaskell.classloader

to create a ClassLoader object.

ClassLoader classloader(Tuple options)

The following items are valid in the "options" tuple:


jaskell.const

to create a function that always return the same value regardless of the parameter.

Function const (Expression val)

The "val" expression is not evaluated until needed


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.

Date add(int fld, int amount, Date date)

Parameters:


jaskell.dates.date

to convert a String to a java.util.Date object.

This function has 3 overloaded versions:

The options parameter can contain the following items:

Refer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.


jaskell.dates.dateformat

to create a java.text.DateFormat object.

This function has 3 overloaded versions:

The options parameter can contain the following items:

Refer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.


jaskell.dates.datepart

to get any field of a date object.

int datepart(int fld, Date date)

The field values are defined in java.util.Calendar.


jaskell.dates.day

to get the day of month of a date. 1st day is 0.

int day(Date date)


jaskell.dates.format

to convert a Date object to a string of desired format.

This function has 3 overloaded versions:

The options parameter can contain the following items:

Refer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.


jaskell.dates.hour

to get the hour of day of a date.

int hour(Date date)


jaskell.dates.millisecond

to get the millisecond of second of a date.

int millisecond(Date date)


jaskell.dates.minute

to get the minute of hour of a date.

int minute(Date date)


jaskell.dates.month

to get the month of a date. January is 0.

int month(Date date)


jaskell.dates.parse

to convert a String to a java.util.Date object.

This function has 3 overloaded versions:

The options parameter can contain the following items:

Refer to jfun.jaskell.optionbeans.MakeDateFormat for the Java Bean class corresponding to the signature.


jaskell.dates.second

to get the second of minute of a date.

int second(Date date)


jaskell.dates.weekday

to get the day of week of a date. Sunday is 1 and Monday is 2.

int weekday(Date date)


jaskell.dates.year

to get the year of a date.

int year(Date date)


jaskell.define

to evaluate an expression with dynamic scope.

This function has 2 overloaded versions:

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.


jaskell.dynamic

the tuple containing functions to dynamically evaluate jaskell code.

jaskell.dynamic.eval

to evaluate a piece of jaskell code dynamically.

This function has 2 overloaded versions:

Parameter Descriptions:


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.

This function has 4 overloaded versions:

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.


jaskell.exception.finally

to ensure that the "finalize_block" will be evaluated after try_block even when try_block results in an exception.

Object finally(Expression try_block, Expression finalize_block)


jaskell.exception.throw

to throw an exception.

void throw(Throwable e)


jaskell.exception.try

to monitor exceptions thrown out of the block.

try(some_expression)

will monitor the exception that might be thrown from evaluating some_expression.


jaskell.exception.within

to recover the uncaught exceptions

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[]))
      


jaskell.flip

to flip the position of the two parameters of a function.

(b->a->c) flip ((a->b->c) f)

"flip (-) 1 2" is equivalent to "2 - 1".


jaskell.id

the parameter is returned directly as return value

Object id(Object val)


jaskell.imperative

functions to do imperative style programming.

jaskell.imperative.for

equivalent to for-loop in Java.

void for(Object init_variable, (Object->boolean) condition, (Object->Object) increment, (Object->Object) loop_body)

Parameters:

"for init (\v->cond v) (\v->inc v) (\v->body)" is equivalent to "for(v=init;cond v;v=inc v){body;}"


jaskell.imperative.foreach

to execute a callback function for each element of a container.

This function has 10 overloaded versions:


jaskell.imperative.get

to get the current value of a refernece.

jaskell.imperative.ref

to create and initialize a mutable reference.

"ref 1" will create a refernece whose initial value is 1.


jaskell.imperative.set

to set the current value of a reference.

"set r 2" will change the value that r references to 2.


jaskell.import

to import a jaskell expression from a jaskell source file.

This function has 2 overloaded versions:

The options tuple can contain the following members:


jaskell.io

io related functions.

jaskell.io.err

the standard error

jaskell.io.err.flush

to flush the output.

void flush()


jaskell.io.err.print

to print a string.

void print(Object msg)


jaskell.io.err.println

to print a string and start a new line.

void println(Object msg)


jaskell.io.out

the standard output

jaskell.io.out.flush

to flush the output.

void flush()


jaskell.io.out.print

to print a string.

void print(Object msg)


jaskell.io.out.println

to print a string and start a new line.

void println(Object msg)


jaskell.java

the tuple with java related functions.

jaskell.java.array

to get the array type of a certain component type.

Class array(Class component_type)

"array(int.class) is equivalent to "int[].class" in Java.


jaskell.java.asTuple

to convert any Java object to a tuple.

This function has 2 overloaded versions:

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.


jaskell.java.getClass

to get the type of an object.

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.


jaskell.java.implements

to implement a Java interface with a jaskell tuple or function.

This function has 2 overloaded versions:

This function has two different overloaded versions:


jaskell.java.import

to load a class dynamically and use this class as a tuple.

This function has 2 overloaded versions:

This function has several different overloaded versions:

The returned tuple can be used as if it were the class. For example:

      import "java.lang.Integer".parseInt["10"]


jaskell.java.instanceof

to find out if an object is an instance of a type.

boolean instanceof(Object obj, Class type)

"obj `instanceof Integer" is equivalent to "obj instanceof Integer" in Java.


jaskell.java.is

to test if the two objects are the same object.

boolean is(Object a, Object b)

"is(a,b)" is equivalent to "a==b" in Java.


jaskell.java.loadClass

to load a class by name.

Class loadClass(String classname)

Same as Class.forName


jaskell.java.synchronized

put a synchronized lock on an object and then evaluate an expression.

Object synchronized(Object some_obj, Expression expr)

"synchronized(obj, some_expr)" is equivalent to:

      
	        synchronized(obj){
	          return some_expr;
	        }
	      

in Java.


jaskell.java.the_method

to get the only method from a type

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.


jaskell.java.toTuple

to convert a Class/Map to a tuple.

This function has 3 overloaded versions:


jaskell.list

list utility functions

jaskell.list.fromArray

to convert an array to a list.

List fromArray(Object[] arr)


jaskell.list.head

to get the 1st element of a list.

Object head(List list)


jaskell.list.nil

same as "[]"

jaskell.list.revArray

to convert a list to an array in reverse order.

Object[] revArray(List list)


jaskell.list.tail

to get the sublist after the 1st element.

List tail(List list)


jaskell.list.toArray

to convert a list to an array.

Object[] toArray(List list)


jaskell.number

functions related to number operator.

jaskell.number.format

to convert a Number object to a string of desired format.

This function has 3 overloaded versions:

The options parameter can contain the following items:

Refer to jfun.jaskell.optionbeans.MakeNumberFormat for the Java Bean class corresponding to the signature.


jaskell.number.numberformat

to create a java.text.NumberFormat object.

This function has 3 overloaded versions:

The options parameter can contain the following items:

Refer to jfun.jaskell.optionbeans.MakeNumberFormat for the Java Bean class corresponding to the signature.


jaskell.number.parse

to convert a String to a Number object.

This function has 3 overloaded versions:

The options parameter can contain the following items:

Refer to jfun.jaskell.optionbeans.MakeNumberFormat for the Java Bean class corresponding to the signature.


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.

Object assert(Object target, Object obj)



jaskell.prelude.assertNe

assert that two objects are not equal. jfun.jaskell.AssertionFailedException is thrown otherwise.

Object assertNe(Object target, Object obj)



jaskell.prelude.assertTrue

assert that an object satisfies a predicate. jfun.jaskell.AssertionFailedException is thrown otherwise.

Object assertTrue((Object->boolean) predicate, (Object->String) messager, Object obj)



jaskell.prelude.assoc

to create a tuple using keys and values stored in a list.

Tuple assoc(List key_vals)

The following code:

      assoc ["name", "tom", "age", 10]

is equivalent to

      {name="tom", age=10}


jaskell.prelude.assoc2

to create a tuple using keys and values stored in two lists respectively.

Tuple assoc2(List keys, List vals)

The following code:

      assoc2 ["name", "age"] ["tom", 10]

is equivalent to

      {name="tom",age=10}


jaskell.prelude.auto

to ensure that an expression is evaluated after another.

"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
        


jaskell.prelude.call

a shortcut of jaskell.callcc

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


jaskell.prelude.cast

to cast an object to a target type using the default jaskell conversion.

Object cast(Class target_type, Object obj)


jaskell.prelude.const

to create a function that always return the same value regardless of the parameter.

Function const (Expression val)

The "val" expression is not evaluated until needed


jaskell.prelude.curry

to convert a function expecting a list object of size n to a new function expecting n parameters.

The folllowing assertion succeeds:

      
       assert(6, plus3 1 2 3) where
         plus3 = curry 3 sum;
       end
      


jaskell.prelude.decimal

to create a BigDecimal value

BigDecimal decimal(Object v)

Either String or Number can be passed in to this function to create a BigDecimal object


jaskell.prelude.default

to specify default values for parameters.

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


jaskell.prelude.define

to evaluate an expression with dynamic scope.

This function has 2 overloaded versions:

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.


jaskell.prelude.do

the monad "do" notation.

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


jaskell.prelude.each

iterate through a list/array using an imperative loop syntax

"foreach [1,2,3] \i->f i" is equivalent to "each {i=[1,2,3]} $ f i"


jaskell.prelude.error

to throw an exception to report an error message.

void error(String msg)


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.

List((Object-boolean) predicate, List)

The folllowing assertion succeeds:

      assert([1,2], filter (3.>) [1,2,3])


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.

int (Object target, List list)

The folllowing assertion succeeds:

      assert(1, find 2 [1,2,3])


jaskell.prelude.flip

to flip the position of the two parameters of a function.

(b->a->c) flip ((a->b->c) f)

"flip (-) 1 2" is equivalent to "2 - 1".


jaskell.prelude.fold

folds a list to a value by repeatedly applying a function to the elements.

seed_type fold((seed_type->elem_type->seed_type) f, seed_type seed, [elem_type] list)



jaskell.prelude.fold2

folds a tuple/Map to a value by repeatedly applying a function to the key/value pairs.

seed_type fold((seed_type->key_type->val_type->seed_type) f, seed_type seed, {key_type=val_type} t)



jaskell.prelude.foldn

folds a collection that's iterable to a value by repeatedly applying a function to the loop variables in each iteration.

seed_type fold(int n, (seed_type->...->seed_type) f, seed_type seed, iterable collection)



jaskell.prelude.foreach

to execute a callback function for each element of a container.

This function has 10 overloaded versions:


jaskell.prelude.id

the parameter is returned directly as return value

Object id(Object val)


jaskell.prelude.in

to determine if an element is contained in a list.

boolean in(Object element, List list)


jaskell.prelude.integer

to create a BigInteger object

BigInteger integer(Object v)

Either String or Number can be passed to this function to create a BigInteger object


jaskell.prelude.iterate

to transform a function to use an imperative loop syntax

"iterate foreach {i=[1,2,3]} $ f i" is equivalent to "foreach [1,2,3] \i->f i".


jaskell.prelude.list

to create a list with elements in the range of [from,to].

List list(int from, int to)

The folllowing assertion succeeds:

      assert([1,2,3], list 1 3)


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.

int lookup((Object->boolean) predicate, List list)

The folllowing assertion succeeds:

      assert(1, lookup (1.<) [1,2,3])


jaskell.prelude.map

to transform a list/map/tuple by applying a function to each element in the container.

This function has 3 overloaded versions:


jaskell.prelude.new

java style "new" operator

Object new(Class clazz, Object[] arguments)


jaskell.prelude.overload

to provide different expressions based on the types of a few variables.

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
      


jaskell.prelude.print

to print a string.

void print(Object msg)


jaskell.prelude.println

to print a string and start a new line.

void println(Object msg)


jaskell.prelude.promote

to create a function that always returns the same value after receiving n parameters.

This is a generalization of the 'const' function.

The folllowing assertion succeeds:

      
          assert("x", const3 "a" "b" "c") where
            const3 = promote 3 "x";
          end
        


jaskell.prelude.puts

to use the key-value pairs stored in a list to functionally update a tuple.

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])


jaskell.prelude.puts2

to use the key-value pairs seperately stored in two lists to functionally update a tuple.

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])


jaskell.prelude.ref

to create a mutable reference of a value.

Tuple ref(Object obj)

Different than 'jaskell.imperative.ref', this function provides more helper utilities.

Description

the returned tuple contains the following member functions:


jaskell.prelude.replicate

To create a list by replicating an object for n times.

List replicate(int n, Object elem)

The folllowing assertion succeeds:

      assert([1,1,1,1], replicate 4 1)


jaskell.prelude.revAppend

to append elements in a list in reverse order to another list.

List revAppend(List append_to, List list)

The folllowing assertion succeeds:

      assert([4,3,2,1], revAppend [4] [1,2,3])


jaskell.prelude.reverse

to reverse the order of elements in a list.

List reverse(List list)

The folllowing assertion succeeds:

      assert([3,2,1], reverse [1,2,3])


jaskell.prelude.sum

to get the sum of all elements in a list.

The folllowing assertion succeeds:

      assert(10, sum[1,2,3,4])


jaskell.prelude.switch

the switch-case idiom.

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
      


jaskell.prelude.throw

to throw an exception.

void throw(Throwable e)


jaskell.prelude.try

the try-catch-finally with a more intuitive syntax.

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:

The return value is a function that has the same form as "jaskell.prelude.try".


jaskell.prelude.typecase

the type-case idiom.

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
        


jaskell.prelude.uncurry

to convert a function expecting n parameters to a new function expecting a list object of size n.

The folllowing assertion succeeds:

      
        assert(3, add[1,2]) where
          add = uncurry 2 (+);
        end
      


jaskell.prelude.value

to make sure an object is not a function.

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.


jaskell.prelude.when

a generalized form of 'switch'.

'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
        


jaskell.prelude.with

to evaluate an expression with all members of an object in scope

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


jaskell.text

string manipulation functions.

jaskell.text.split

to split a string into an array

String[] split(String delim, String str)


jaskell.tuple

contains functions to manipulate tuples.

jaskell.tuple.at

to get an element identified by a key

This function has 7 overloaded versions:


jaskell.tuple.containsKey

to test if a key is present in an associative array

This function has 3 overloaded versions:

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


jaskell.tuple.extends

to "extend" tuple t2 with tuple t1.

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.


jaskell.tuple.includes

to create a tuple that includes members from both t1 and t2.

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.


jaskell.tuple.keys

to get the member keys of a tuple.

List keys(Tuple t)

The keys are put into a list.

he order of the keys are not defined.


jaskell.tuple.keys_array

to get the member keys of a tuple.

Object[] keys_array(Tuple t)

The keys are put into an array.

he order of the keys are not defined.


jaskell.tuple.put

dynamically extend/override a tuple member.

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.


jaskell.tuple.remove

to create a new tuple by removing one member.

Tuple remove(Tuple t, Object key)

Note, this is functional remove, the original Tuple is not changed.


jaskell.tuple.removes

create a tuple by removing a list of members

This function has 3 overloaded versions:

Note, this is functional update. The original Tuple is not changed.


jaskell.tuple.sizeof

to get the size of a container

This function has 4 overloaded versions:


jaskell.tuple.subtuple

dynamically create a sub-tuple.

This function has 2 overloaded versions:

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.


jaskell.util

general utility functions.

jaskell.util.properties

to read a property file as a tuple.

This function has 2 overloaded versions:

The following items can be specified in the "options" parameter:

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


jaskell.version

to get the current version of jaskell.

jaskell.with

to evaluate an expression with all members of an object in scope

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


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

Object assertEquals(Tuple options)

lists, arrays, tuples, maps are automatically coersed and compared by content.

The options tuple can contain the following members:


junit.assertError

to assert that an expression throws a certain exception.

Object assertError(Tuple options)

The options tuple can contain the following members:


junit.assertInstanceof

To assert that an object is an instance of a type.

Object assertInstanceof(Tuple options)

The options tuple can contain the following members:


junit.assertNotEquals

to assert that two objects are not equal

Object assertNotEquals(Tuple options)

lists, arrays, tuples, maps are automatically coersed and compared by content.

The options tuple can contain the following members:


junit.assertNotNull

to assert that an object is not null.

Object assertNotNull(Tuple options)

The options tuple can contain the following members:


junit.assertNotSame

to assert that two objects are not same

Object assertNotSame(Tuple options)

The options tuple can contain the following members:


junit.assertNull

to assert that an object is null.

Object assertNull(Tuple options)

The options tuple can contain the following members:


junit.assertSame

to assert that two objects' identity are same

Object assertSame(Tuple options)

The options tuple can contain the following members:


junit.assertTrue

to assert that an object is true.

Object assertTrue(Tuple options)

The options tuple can contain the following members:


junit.fail

to report failure.

void fail(String msg)

when null is passed as the "msg" parameter, the Assert.fail() method is invoked instead.


not

equivalent to the '!' operator

not true == false


now

to get the current time.

Equivalent as "new Date()" in Java.


null

the null value

Same as "null" in Java.


synchronized

put a synchronized lock on an object and then evaluate an expression.

Object synchronized(Object some_obj, Expression expr)

"synchronized(obj, some_expr)" is equivalent to:

      
	        synchronized(obj){
	          return some_expr;
	        }
	      

in Java.