6.1 Description of methods and operators  naver/lispe Wiki
Operators
Here is an exhaustive description of the operators provided by LispE. Note that when these operators can applied to one single list, in which case, they apply this operation to all elements inside.
%: remainder of an integer division
(% 10 3) ; gives 1
*: multiplication
(* 10 2) ; gives 20
+: numerical addition or concatenation of strings
(+ 10 20) ; gives 30
(+ "test" "=" "empty") ; gives "test=empty".
: subtraction
Be careful to put a space after the minus, otherwise the interpretation will be that of a negative number.
( 10 2) ; gives 8
/: division
(/ 10 6) ; gives 1.66667
<<: left shift
(<< 10 1) ; gives 20
>>: right shift
(>> 10 1) ; gives 5
^^: power
(^^ 10 2) ; gives 100
&: bitwise and
(& 10 2) ; gives 2
&~: bitwise and not
(&~ 10 2) ; gives 8
: bitwise or
( 10 6) ; gives 14
^: bitwise xor
(^ 10 2) ; gives 8
~: bitwise not
(~ 10) ; gives 11
!: factorial of n
(! 6) ; yields 720
Operation and local modification
All operators can be used in the form: +=, *=, /= etc.
The only constraint is that the first element must be a variable.
; We create a variable:
(setq r 10)
(+= r 10)
; r is now 20
Operators on Lists
The following operators take two lists, sets or strings and apply an intersection, a union, or an exclusive union (xor). These operators then generate a new element, which contains some elements from both objects, without any duplicates.
intersection: (&&& o1 o2)
The intersection returns a list (string or set), which contains the elements that exist in both objects.
(setq r '(10 20 30 40 30 40))
(setq v '(10 2 2 60 30 4 50 60))
(&&& r v) ; (10 30)
; With sets
(setq r (seti 10 20 30 40))
(setq v (seti 10 2 30 4 50 60))
(&&& r v) ; {10 30}
; with strings
(setq r "aabbccdfedefghij")
(setq v "acaeeegik")
(&&& r v) ; acegi
union: ( o1 o2)
The union returns a list (string or set), which contains all the elements from both objects.
(setq r '(10 20 30 40 30 40))
(setq v '(10 2 2 60 30 4 50 60))
( r v) ; (10 20 30 40 2 60 4 50)
; With sets
(setq r (seti 10 20 30 40))
(setq v (seti 10 2 30 4 50 60))
( r v) ; {2 4 10 20 30 40 50 60}
; with strings
(setq r "aabbccdfedefghij")
(setq v "acaeeegik")
( r v) ; abcdfeghijk
exclusive union: (^^^ o1 o2)
The exclusive union returns a list (string or set), which contains a union of both lists minus the common elements.
(setq r '(10 20 30 40 30 40))
(setq v '(10 2 2 60 30 4 50 60))
(^^^ r v) ; (20 40 2 60 4 50)
; With sets
(setq r (seti 10 20 30 40))
(setq v (seti 10 2 30 4 50 60))
(^^^ r v) ; {2 4 20 40 50 60}
; with strings
(setq r "aabbccdfedefghij")
(setq v "acaeeegik")
(^^^ r v) ; bdfhjk
Infix
The way mathematical formulas are written in LispE do not always make the expressions very readable. LispE provides a specific operator: infix that allows mathematical expressions to be written infixed. The only constraint is that operators and operands must be separated with a space.
These expressions are compiled on the fly and replaced in the code with their actual LispE interpretation. The way the expression is compiled takes into account the traditional notion of operator precedence.
It is also possible to have an idea of how these expressions are actually compiled if you put them in a lambda in the console, which is then compiled into the final expression. Furthermore, note that the infix operator only applies to the top expression in parentheses. If you have a subexpression within the expression, you will need to use the infix operator again.
infix or /\ or • or §
Each of these four operators is equivalent.
; This is compiled as (lambda (x) ( (+ 10 20) (* 4 x)))
(lambda (x) (infix 10 + 20  4 * x))
; This is compiled as (lambda (x) ( (+ (^^ x 3) (* 10 (^^ x 2)) (* 2 x)) 1))
(lambda (x) (• x ^^ 3 + 10 * x ^^ 2 + 2 * x  1))
; This is compiled as (lambda (x) ( (+ (* 10 (^^ ( x 1) 2)) (* 2 ( 4 x))) 1))
; If you don't use the infix operator in an expression, you need to write it as usual
(lambda (x) (/\ 10 * (§ x  1) ^^ 2 + 2 * ( 4 x)  1))
(infix list)
If infix is provided with a list or a variable, then the transformation is applied during the execution.
(infix '(12 + 30)) ; (+ 12 30)
Operations With Lists
Note that all these operators can recursively apply between lists:
; Operation between two or more lists
(+ '(1 2 3) '(4 5 6) '(3 2 1)) ; yields (8 9 10)
; Operation with a scalar
( '(10 9 8) 4) ; yields (6 5 4)
; Operation with a list of lists and another list
(+ '((1 2 3) (4 5 6 7) (1 1 1)) '(2 2 2)) ; yields ((3 4 5) (6 7 8 9) (3 3 3))
Comparisons
The comparison operators are as follows:
=: equal
The difference with eq is that eq does not recursively compare lists or dictionaries, while = does.
(= 10 10) ; yields true
(= '(1 2 3) '(1 2 3)) ; yields true
!=: different
(!= 10 20) ; yields true
(!= '(1 2 R) '(1 2 A)) ; yields true
<: less
(< 10 100) ;gives true
<= : less or equal
(<= 10 10) ;gives true
>: more
(> 10 5) ; gives true
>=: greater or equal
(>= 10 10) ; gives true
Functions
Here is an exhaustive description of the functions provided by LispE.
@: (@ container k1 k2 k3...kn)
Returns the value corresponding to a sequence of keys. The container can be a list, a matrix, a tensor or a dictionary.
(setq r (rho 2 2 (iota 5))) ; r = ((1 2) (3 4))
(println (@ r 0 1)) ; is 2
and: (and cond1 cond2 cond3)
And logical
(and (< 10 100) (>= 10 10)) ; gives true
apply: (apply fonc list)
applies a function to the following arguments
(apply '+ '(1 2 3 4)) ; gives 10
(setq f '*)
(apply f '(2 3 4)) ; gives 24
at (at container k (value))
at works as "@", however it can only apply one level of keys. If a value is provided, it will modified the container at the position corresponding to the key. Note that for matrices and tensors, you can provide indexes up to the shape of the container, in order to store a value. It is better to use [email protected] or @.
(setq l (iota 10))
(println (at l 1)) ; yields 2
(at l 1 100) ; yields (1 100 3 4 5 6 7 8 9 10)
(setq m (rho 3 3 (iota 10))) ; the shape is 3x3
(at m 1) ; yields (4 5 6)
(at m 1 1) ; yields 5
; we cannot go beyond two indexes for a matrix
(at m 1 1 100) ; yields ((1 2 3) (4 100 6) (7 8 9))
atomp: (atomp e)
returns true if the argument is an atom
(atomp 'e) ; returns true
atoms: (atoms)
returns the list of atoms stored at the top of the execution stack
(atoms) ; at the root returns:
(fpiecewise_linear_distribution piecewise_constant_distribution discrete_distribution log cosh cos cbrt asin alphap second hour etc.).
block
allows the evaluation of a list of lists
(if (eq x 10)
(block
(print x)
1
)
(+ x 1)
)
bodies: (bodies name)
Returns the list of bodies for defpat function definitions
break
Allows you to exit a "loop".
car, cdr, cadr, caadr
 car returns the first element of a list
 cdr returns the list following the first item.
Variations can also be made by mixing the a and r. For example caadr corresponds to (car (car (cdr l))).
(car '(1 2 3)) ; gives 1
(cdr '(1 2 3)) ; gives '(2 3))
(cdar '((1 5) 2 3)) ; gives (5) equivalent to (cdr (car '((1 5) 2 3)))
catch
catch is used to capture errors as a way to prevent programs from stopping.
catch acts as a block. It takes a list of instructions and stops at the first error. It then returns a maybe object that contains the error message. You can then use the instruction maybe to check if an error occurred while running the code.
(setq c
(catch
(setq e 10)
(setq v 0)
(cons ' a)
)
)
(if
(maybe c)
(print Error: c)
(print No error)
)
check: (check CONDITION I1...In)
If CONDITION is true, execute the list of instructions: I1,I2... to In
.
(setq k 10)
; if k < 100, we increment it
(check (< k 100)
(println k)
(+= k 1)
)
cond: (cond (cond1 action1) (cond2 action2)...(true final_action))
Allows to chain multiple conditions
(cond
(
(< x 10)
(print x is smaller than 10)
)
(
(< x 100)
(print x is smaller than 100)
)
(true
(print x is greater than 100)
)
)
cons: (cons e l)
builds a list by merging the first item into the next one.
(cons 'a ()) ; gives (a)
consp: (consp e)
returns true if the argument is a list
(consp '(1 2 3)) ; returns true
containerkeys: (containerkeys dict)
Returns the keys of a container
(print (containerkeys d))
containervalues: (containervalues dict)
Returns values from a dictionary (see containerkeys)
count: (count o u pos)
Counts the number of times u is in o
(count "abcdefabdefabghabtr" "ab") ; yields 4
cyclicp: (cyclicp e)
returns true if the argument is a linked list that contains cycles
(setq l (llist 10 20 30))
(extend l l)
(cyclicp l) ; yields true
data: Define data structures
data is used to defined data structures, which can be used to organise data and types.
see: Data Structures for more information.
defmacro
defmacro helps define your own macros. A macro is a piece of code that is replaced on the fly within your functions. When you use a macro, there is no call to a function, since the code has been replaced with the macro instructions.
Note: You can use any variable names in the macros. Actually, when the macro is compiled, its variable names are replaced with specific macro names that cannot be confused with LispE declarable names.
; this macro returns true if a value is in a list
(defmacro in (x l) (not (nullp (find l x))))
; You simply use the name as if it was a function name.
(println (in 1 '(1 2 3 4)))
; whose underlying structure is now:
(println (not (nullp (find '(1 2 3 4) 1))))
deflib: Internal interpreter use:
see Enrich LispE
defun: (defun label (param1 param2...) code)
allows you to define a function. defun consists of a name followed by a list of arguments and the body of the function.
(defun add (x y) (+ x y))
defpat: (defpat label (param1 param2...) code)
allows you to define pattern matching functions. Note that the function name can be defined more than once, each with a different pattern.
see: Pattern Functions for more information.
dethread: (dethread label (param1 param2...) code)
dethread allows you to declare a thread. The main thread can then wait for all these threads to end their execution.
; we define a thread
(dethread call(s i)
(loop e (range 0 i 1)
(+= s (string e))
)
(println s)
)
; We call 3 threads with different arguments
(call "l:" 10)
(call "x:" 20)
(call "y:" 30)
; we wait for these threads to end
(wait)
droplist: (droplist condition list)
 This function is very similar to dropwhile however, it cannot compose with other high level functions such as map, takewhile or drop.
 Second, the value from the list is always appended at the end of the condition.
As such, it is not expanded into a loop instruction as takewhile and is much faster.
droplist drops elements from a list until the condition complies with a value. It then returns the remainder of the list.
(droplist '(< 10) '(1 4 5 11 9 11 20)) returns (11 9 11 20) ; it applies (< 10 x)
(droplist (lambda (x) (> x 10)) '(1 4 5 10 11 9 20)) returns (11 9 20)
(duplicate struct)
Duplicates the structure.
eq/neq: (eq e1 e2)
comparison between two elements to verify equality
neq
corresponds to (not (eq ..))
(setq x 100)
(eq x 100) ; returns true
emptyp: checks if a list is empty
(emptyp '()) ; true
eval
Allows to evaluate a string as a Lisp expression or to evaluate a list.
(eval (list 'cons ''a '''(1 2 3))) ; gives (a 1 2 3)
(eval "(cons 'a '(1 2 3))") ; also gives
explode: (explode string)
allows to transform a string into a list of atoms.
(explode "abcd") ; yields (a b c d)
extract: (extract e i1 (i2)), i2 is optional
allows to extract a sublist between two indexes or a substring between numerical indexes or substrings. It is possible to give negative indexes which are then calculated from the end of the list or the string.
In the case of a string if the first index is also a string and the second index a number, then this number defines the number of characters to be extracted.
If only one argument is given, the function is equivalent to "at".
operators: +, 
These two operators must be placed just before the doublequotes.
 The
+
indicates that the searched string must be part of the final string.  The

indicates that the search must be done reverse from the end of the string.  The
+
combines the two operators. The search is done reverse with it being part of the final string.
(extract '(1 2 3 4 5) 1 3) ; gives (2 3)
(extract "12345" 1 3) ; gives "23".
(extract "abcdefghij" "b" "e") ; gives "cd".
(extract "abcdefghij" +"b" +"e") ; gives "bcde".
(extract "abcdefghij" "b" 3) ; gives "cde".
(extract "abcdefghij" +"b" 3) ; gives "bcde".
(extract "12345" 2) ; gives "4".
(extract "12345" 1 1) ; gives "234".
(extract "/home/test/titi/toto/name.txt" "/" 0) ; yields "name.txt"
(extract "/home/test/titi/toto/name.txt" +"/" 0) ; yields "/name.txt"
fappend: (fappend pathname data)
writes a string at the end of a file
filterlist: (filterlist condition list)
 This function is very similar to filter however, it cannot compose with other high level functions such as map, takewhile or drop.
 Second, the value from the list is always appended at the end of the condition.
As such, it is not expanded into a loop instruction as filter and is much faster.
(filterlist '(< 10) '(1 4 5 10 11 20)) returns (11 20), we test (< 10 list_value)
; Note that (filter '(< 10) '(1 4 5 10 11 20)) returns (1 4 5)
(filterlist (lambda (x) (< x 10)) '(1 4 5 10 11 20)) returns (1 4 5)
find: (find e o pos)
returns the position of e
in o
or nil
. o
is either a list or a string.
(find "abcdef" "bc") ; gives 1
(find "abcdef" "bd") ; gives nil
findall: (findall string string pos)
returns a list of all positions of the substring in the string.
(findall "abcdefabdefabghabtr" "ab") ; gives (0 6 11 15)
flatten: (flatten l)
Flatten a list or a dictionary.
(flatten '( ( (1 2) (3 4)) (5 6))) ; yields (1 2 3 4 5 6)
float: (float e)
converts a string into a float (32 bits)
(float "12.3") ; gives 12.3
floats: (floats e)
Converts a list into list of floats. e can also be more than one elements.
(floats '(1.2 3.3 4 5))
(floats 1.2 3.3 4 5) ; is also acceptable
flip: (flip (f x y))
flips the two first arguments of a function.
Note: If you use flip on a dictionary, it will reverse keys and values.
(flip ( 10 2)) ; yields: 8
fread: (fread pathname)
reads a text file (UTF8) and returns the corresponding string: (fread "file")
fwrite: (fwrite pathname data)
writes a string to a file
if: (if (predicate) THEN ELSE)
test the predicate, if it's true execute THEN if not ELSE. ELSE is optional.
(if (eq x 10) (println true) (println false))
ife: (ife (predicate) THEN ELSE_BLOCK)
test the predicate, if it's true execute THEN if not ELSE. The ELSE is actually a block of instructions.
; if x ≠ 10 then (setq x 20) and (println false) will be executed
; otherwise only (println true)
(ife (eq x 10) (println true) (setq x 20) (println false))
in: (in e o pos)
returns true or nil
if e
in o
. o
is either a list or a string.
(in "abcdef" "bc") ; gives true
(in "abcdef" "bd") ; gives nil
input
Allows to read an input from keyboard.
You can also provide a string that can be modified in input
; keyboard reading of a string
(setq v (input))
; We can also modify the content of v again
(setq v (input v))
integer: (integer e)
converts a string into an integer value
(integer "12") ; gives 12
integers: (integers e)
converts a list into list of integers. e can also be more than one elements.
(integers '(1 3 4 5))
(integers 1 3 4 5) ; is also acceptable
insert: (insert l e idx)
Inserts the e element in l at the idx position.
l can be a list or a string
(insert '(1 2 3) 4 1) ; gives (1 4 2 3)
join: (join l sep)
transforms a list of atoms into a string
(join '(a b c) '/) ; gives "a/b/c".
key: Dictionary indexed on strings of characters
Four actions:
(key)
: creates a dictionary(key k v k' v' k" v"...)
: Creates a dictionary with key/value couples(key d k v k' v' k" v"...)
: sets key/value couples in dictionary d(key d k)
: returns the value in the dictionary d for key k
; We create a dictionary
(setq d (key))
; Values are added to the dictionary
(key d "a" "e" "b" "c" "d" "e")
; We display the value for the key "a".
(println (key d "a"))
keyi: Dictionary indexed on integers
(keyi)
: creates a dictionary(keyi k v k' v' k" v"...)
: Creates a dictionary with key/value couples(keyi d k v k' v' k" v"...)
: sets key/value couples in dictionary d(keyi d k)
: returns the value in the dictionary d for key k
; We create a dictionary
(setq d (keyi))
; We add a value in the dictionary
(keyi d 12 "e" 17 "b" 15 "hh")
; The value for key 12 is displayed.
(println (keyi d 12))
keyn: Dictionary indexed on numbers
(keyn)
: creates a dictionary(keyn k v k' v' k" v"...)
: Creates a dictionary with key/value couples(keyn d k v k' v' k" v"...)
: sets key/value couples in dictionary d(keyn d k)
: returns the value in the dictionary d for key k
; We create a dictionary
(setq d (keyn))
; We add a value in the dictionary
(keyn d 12 "e" 17 "b" 15 "hh")
; The value for key 12 is displayed.
(println (keyn d 12))
label: (label lab exp)
Saves the argument under the provided label
(label myLabel (lambda (x) (eq x 10))
lambda: definition of a lambda function
Note that we accept \
and λ (Unicode 955)
as substitute characters for the keyword lambda
( (lambda (x y) (+ x y)) 10 20)
( (\ (x y) (+ x y)) 10 20)
( (λ (x y) (+ x y)) 10 20)
last: (last e)
returns the last element of a list or the last character of a string.
(last '(1 2 3)) ; returns 3
link: (link str atom)
Create a string that shares the same id as a given atom. This is especially useful to modify the behaviour of the tokeniser in LispE.
(see cosine for an example)
; "BEGIN" and "END" have now the same ids as '( and ')
(link "BEGIN" (atom "("))
(link "END" (atom ")"))
; It is now possible to evaluate as if it was: (+ 10 20)
BEGIN + 10 20 END
; we replace the + sign with the *
(link "+" '*)
(+ 10 20) ; is now 200
list: (list e1 e2 ..)
creates a list from the arguments
(list 'a 12 34) ; gives (a 12 34)
llist: (llist e1 e2 ..)
Creates a linked list from the arguments.
A linked list is a list where each element is linked to the next through a pointer.
A linked list can contain cycles.
 push and pop push and remove an element at the beginning of a linked list by default.
 cdr can indefinitely loop if the list contains a cycle.
 loop will detect any cycle and will stop once all elements have been visited.
; or a list of elements as for a regular list operation
(setq ll (llist 10 20 30))
(push ll 100) ; yields (100 10 20 30)
(extend ll ll) ; connects then end of the list with its beginning creating a cycle
; The following code will loop 6 times in this 4 elements cyclic list
(loopcount 6
(setq ll (cdr ll))
(println ll)
)
; To create a linked list out of a list
(setq lbis (to_llist (list 20 30 40 50)))
; the ... indicates that the list contains a cycle
(10 20 30 100 ...)
(20 30 100 10 ...)
(30 100 10 20 ...)
(100 10 20 30 ...)
(10 20 30 100 ...)
(20 30 100 10 ...)
load: (load filename)
loads and runs a LispE program provided as a file.
(setq tst (load "file.lisp"))
lock: (lock key instructions)
This instruction protects a block of instructions in a thread. key is a string that is used to identify the lock. It is implemented as a recursive mutex.
loop: (loop var list instruction1 instruction2...)
allows to iterate on a list or a string: (loop var list instruction)
. The last element of the iteration returns the final result.
(loop i '(1 2 3)
(print i)
(+ i 2)
)
(lloop (x1 x2 x3...) l1 l2 l3... instructions)
lloop is used to iterate in parallel among different lists.
To iterate on different types, such as dictionaries, use: mloop.
In that case, you need to provide as first argument, a list of variables and next to it a succession of lists, whose number must match the number of variables.
; x will loop on (1 3 4)
; y will loop on (5 6 7)
; z will loop on (9 10 13)
(lloop (x y z) '(1 3 4) '(5 6 7) '(9 10 13) (println (+ x y z)))
; 15
; 19
; 24
loopcount: (loopcount nb instruction1 instruction2...)
allows to iterate nb times. The last element of the iteration returns the final result.
(setq i 0)
(loopcount 10
(print i)
(+= i 2)
)
maplist
This instruction is similar to map. It offers a much faster implementation. However, it cannot compose with other high level functions such as filter or takewhile. Furthermore, it can only apply functions of arity 1.
(maplist (lambda(x) (+ x x)) (iota 10)) ; (2 4 6 8 10 12 14 16 18 20)
mark
This instruction is used with lists to handle potential list infinite loops. It has two different utilisations:
(mark l B)
: marks the list with the Boolean value: B(mark l)
: returns the Boolean value attached to this list...
Note that in the case of an infinite loop, the list is displayed with: '...' instead of the element that is infinitely repeated:
(setq a '(1 2 3))
(setq b '(10 20 30))
; we create an infinite loop
(push a b)
(push b a)
(println a) ; display: (1 2 3 (10 20 30 ...))
(println b) ; display: (10 20 30 (1 2 3 ...))
; Looping in the structure
; when mark is true, we stop ans display a warning message
(defun traverse (l)
(check (consp l)
(ife (mark l)
(println "Warning: infinite loop")
(println (at l 0))
(mark l true)
(traverse (car l))
(traverse (cdr l))
(mark l false)
)
)
)
(traverse a)
maybe
This instruction checks whether a value returned by catch was an error or detects errors in a sequence of instructions.
maybe exposes two different modes:
 It has one single argument, then it returns true if the value is a maybe object returned by a catch.
 It has at least two arguments. Each instruction is executed in sequence except for the last one. If one instruction fails, then the last one is executed.
(setq c
(catch
(cons ' a)
)
)
; With one parameter, we can then use the caught value to display an error message
(if
(maybe c)
(print Error: c)
(print No error)
)
; with more than one parameters
; if an error occurs in one of the instructions, then the last instruction is executed...
(maybe (cons 'a ())
(cons 'b ())
(cons 'c)
(println "An error occurred")
)
max: (max a1 a2 a3) / (max '(e1 e2 e3))
Returns the largest element in a string of arguments or the largest element in a list.
(max 1 4 5 10 8) ; returns 10
(max '(1 4 5 10 8)) ; returns 10
min: (min a1 a2 a3) / (min '(e1 e2 e3))
Returns the smallest element in a string of arguments or the smallest element in a list
(min 1 4 5 10 8) ; returns 1
(min '(1 4 5 10 8)) ; returns 1
minmax: (min a1 a2 a3) / (minmax '(e1 e2 e3))
Returns a list containing the largest and the smallest element in a list
(minmax 1 4 5 10 8) ; returns (1 10)
mloop : (mloop (x1 x2 x3...) c1 c2 c3... instructions)
mloop is used to iterate in parallel among different containers that are not all lists.
In that case, you need to provide as first argument, a list of variables and next to it a succession of lists, whose number must match the number of variables.
; x will loop on (1 3 4)
; y will loop on {"a":10 "b":20 "c":4} (actually on the values not the keys)
; z will loop on (9 10 13)
(mloop (x y z) '(1 3 4) {"a":10 "b":20 "c":4} '(9 10 13) (print (+ x y z)))
; 14
; 33
; 27
ncheck: (ncheck CONDITION ELSE_I I1...In)
If CONDITION is true, execute the list of instructions: I1,I2... to In
.
If CONDITION is nil, execute ELSE_I
.
(setq k 10)
; if k < 100, we increment it
(ncheck (< k 100)
(println 'end) ; if k == 100, we stop and display a message
(println k)
(+= k 1)
)
nconc: (nconc l1 l2 l3...x)
List concatenation. All arguments should be a list except for the last one. The concatenation is made into the first argument...
(nconc) is nil
(setq x '(a b c)) => (a b c)
(setq y '(d e f)) => (d e f)
(nconc x y) => (a b c d e f)
; x is now (A B C D E F)
nconcn: (nconcn l1 l2 l3...x)
List concatenation. All arguments should be a list except for the last one. The concatenation creates a new list... nconcn is identical to nconc except for the fact that it creates a new list.
(nconcn) is nil
(setq x '(a b c)) => (a b c)
(setq y '(d e f)) => (d e f)
(nconcn x y) => (a b c d e f)
; x is not modified
not: (not e)
Boolean Negation: (not true) gives false
nullp: test if the argument is nil
number: (number e)
converts a string into a number
(number "12") ; gives 12
numberp: check if the argument is a number
numbers: (numbers e)
converts a list into list of numbers. e can also be more than one elements.
(numbers '(1.2 3.3 4 5))
(numbers 1.2 3.3 4 5) ; is also acceptable
or: or Boolean
(or (eq 10 20) (eq 20 20)) ; returns true
pipe: (pipe)
Read the pipe
on the command line...
Return nil
when the pipe is empty...
; As long as there is data in the pipe, we read it...
(setq p (pipe))
(while p (setq p (pipe))
pop: (pop e cle)
Removes a value from a list, a dictionary or a string.
(pop '(A b c) 1) ; gives (A c)
(pop {12:34} 12) ; gives {}.
(pop "abc" 2) ; gives "ab".
popfirst: (popfirst e)
Removes the first value from a list or a string.
(popfirst '(A b c)) ; gives (b c)
(popfirst "abc") ; gives "ab".
poplast: (poplast e)
Removes the last value from a list or a string.
(poplast '(A b c) 1) ; gives (A b)
(poplast "abc" 2) ; gives "ab".
prettify: (prettify l)
Displays in a more readable form a parenthesized structure.
print: (print e1 e2 .. en)
Displays the values on the screen
println: (println e1 e2 .. en)
Displays the values on the screen by separating them with a space and placing a carriage return at the end.
printerr: (printerr e1 e2 .. en)
Displays the values on the screen on stderr.
printerrln: (printerrln e1 e2 .. en)
Displays the values on the screen by separating them with a space and placing a carriage return at the end, on stderr.
push: (push l a)
adds an item to the l list. Be careful, if the list is a constant element, this operation returns a copy.
(push '(1 2 3) 4) ; returns (1 2 3 4) which is a copy of the initial list.
; So, pay attention to the following code:
(push '(1 2 3) 12) ; returns a copy of the list
pushfirst: (pushfirst l a)
adds an item at the beginning of the l list. Be careful, if the list is a constant element, this operation returns a copy.
(pushfirst '(1 2 3) 4) ; returns (4 1 2 3) which is a copy of the initial list.
; So, pay attention to the following code:
(pushfirst '(1 2 3) 12) ; returns a copy of the list
pushlast: (pushlast l a)
adds an item at the end of the l list. Be careful, if the list is a constant element, this operation returns a copy.
(pushlast '(1 2 3) 4) ; returns (1 2 3 4) which is a copy of the initial list.
; So, pay attention to the following code:
(pushlast '(1 2 3) 12) ; returns a copy of the list
quote: (quote arg)
The operator associated with '. Returns without evaluating its argument.
range: (initial range does not limit)
Returns a list of values starting at initial, ending at limit in steps.
These lists are either a numbers type or an integers type according to the different values given as arguments
(range 1 10 1) ; yieds (1 2 3 4 5 6 7 8 9), which is an 'integers' type
Exits a loop or a function and returns its argument.
replaceall: (replaceall object search replace)
Replaces all the occurrences of search in object with replace. Returns the number of replacements.
object can be any container or a string.
(setq l (integers 10 20 10 40))
(setq nb (replaceall l 10 100)) ; nb is 2 and l is now: (100 20 100 40)
resetmark
Resets the marks on lists for control over infinite loops.
rotate: (rotate x (left))
Rotate values from a list or a string to the right or the left. By default the rotation is done to the right, when left is not assigned.
(rotate "abcde") ; yields "eabcd"
(rotate "abcde" true) ; yields "bcdea"
(rotate (iota 10)) ; yields (10 1 2 3 4 5 6 7 8 9)
(rotate (iota 10) true) ; yields (2 3 4 5 6 7 8 9 10 1)
return: (return a)
Exit a function and return a value
(function call(i)
(while (< i 10)
(if (eq i 5)
(return i)
(= i 1)
)
)
)
⌽: reverse: (reverse l local)
Reverse a string or a list.
local is optional and has two possible values:
 true: in this case the list is reversed locally.
 a numerical value: this value is an axis along which a matrix or a tensor is reversed. If you apply a reverse on a matrix or a tensor, then these containers are reversed along their last axis.
(reverse '(a b c)) ; gives (c b a)
(reverse "abc") ; gives "cba".
(setq l (iota 10) true) ; l is (1 2 3 4 5 6 7 8 9 10)
(reverse l true) ; l is now (10 9 8 7 6 5 4 3 2 1)
(setq m (rho 3 2 (iota 6))) ; m is ((1 2) (3 4) (5 6))
(reverse m) ; yields ((2 1) (4 3) (6 5)). The default axis is 1.
(reverse m 0) ; yields ((5 6) (3 4) (1 2))
rfind: (find string subch)
Search for a substring of characters from the end.
select: (select c1 c2 c3...)
Returns the first non nil
value.
; returns either a value in the dico if the key is present of the key itself
(select (key dico k) k)
self: (self e1 e2...)
Allows to make a recursive call in a function or lambda.
( lambda (x) (if (eq x 1) 1 (+ x (self ( x 1))))) 12))
set: set, sets, setn, seti
Creates sets of elements.
sets, setn, seti create respectivement:
 sets: set of strings
 seti: set of integers
 setn: set of numbers
set is used to create sets of objects.
An element is pushed into a set with either insert or push.
An element is removed from a set with pop.
 You can check if an element belong to a set with in.
 You can access an element in a set with @.
 You can loop on all values in a set.
(setq strset (sets "ab" "cd" "ef"))
(push strset "ok")
(if (in s "ok") 'ok 'no)
(setq o_set (set '(1 2 3) '(1 2) '(8 9))
(println (type (@ o_set '(1 2))) ; list_
[email protected]: ([email protected] container k1 k2 k3...kn value)
Set a value at the position corresponding to the sequence of keys
(setq r (rho 2 2 (iota 5))) ; r = ((1 2) (3 4))
([email protected] r 0 1 100)) ; r is now ((1 100) (3 4))
setg: (setg label value)
Initialization of a global variable with a value
setq: (setq label value)
Initialization of a variable with a value
setrange: (setrange container beg end value)
Replaces a range of values between beg and end with value.
This method utilizes the same interval description as extract.
(setq r '(1 2 3 4 5 6))
(setrange r 0 3 100) ; r is now (100 5 6)
short: (short e)
converts a string into a short (16 bits)
(short "12") ; gives 123
shorts: (shorts e)
Converts a list into list of shorts. e can also be more than one elements.
(shorts '(12 33 4 5))
(shorts 12 33 4 5) ; is also acceptable
sign: (sign e)
Changes the sign of e.
(sign 10) ; 10
(sign 10) ; 10
signp: (signp e)
 If e is negative: returns 1
 If e is 0: returns 0
 If e is positive: returns 1
size: (size e)
Returns the size of a list or a string
sleep: (sleep tm)
Put a thread in sleep mode for tm milliseconds.
sort: (sort comparator list)
Sort a list. Important, the comparator must not return true in case of a tie. Thus <=
is a bad comparison operator.
(sort '< '(1 7 9 4 3)) (1 3 4 7 9)
(sort '> '(1 7 9 4 3)) (9 7 4 3 1)
string: (string e)
Converts its argument into a string
stringf: (stringf n format)
Converts its argument (a number) into a string with a format based on C function printf.
(stringf 123 "0x%X") ; is 0x7B
stringp: (stringp e)
Check if e
is a string
strings: (strings e)
converts a list into list of strings. e can also be more than one elements.
(strings '("a" "b" "c" "d"))
(strings "a" "b" "c" "d") ; is also acceptable
takelist: (takelist condition list)
 This function is very similar to takewhile however, it cannot compose with other high level functions such as map, takewhile or drop.
 Second, the value from the list is always appended at the end of the condition.
As such, it is not expanded into a loop instruction as takewhile and is much faster. takelist extracts elements from a list that comply with the condition. It stops when an element does not comply anymore.
(takelist '(> 10) '(1 4 5 10 9 11 20)) returns (1 4 5) ; it applies (> 10 x)
(takelist (lambda (x) (< x 10)) '(1 4 5 10 11 20)) returns (1 4 5)
to_list: (to_list object)
This instruction transforms any kind of container into a list.
(to_list (numbers 10 20 30)) ; is now a list
to_llist: (to_llist object)
This instruction transforms any kind of container into a llist (linked list).
(to_llist (list 10 20 30)) ; is now a llist
threadretrieve: (threadretrieve namespace)
This instruction returns the data that were stored in the protected list with threadstore, within a thread. namespace is a string that defines a namespace in which your data is stored. You can implement as many namespaces as you want.
If you use threadretrieve
without any namespace, it returns a dictionary containing all the namespaces and their values.
(dethread call(i)
(setq l (range 1 i 1))
; our namespace is "here":
(threadstore "here" l)
)
(call 10)
(call 100)
(call 20)
(wait)
(println (threadretrieve "here"))
threadstore: (threadstore namespace e)
This instruction should be used in a thread to store elements that should survive the thread itself. This instruction stores the information in a protected list that can be accessed through retrieve. namespace is a string that defines a namespace in which your data is stored. You can implement as many namespaces as you want.
(dethread call(i)
(setq l (range 1 i 1))
(threadstore "other" l)
)
threadclear: (threadclear namespace)
Clear the protected list used in threads to keep data alive. namespace is a string that defines a namespace in which your data is stored. You can implement as many namespaces as you want.
If you do not provide any namespace, then all spaces will be deleted.
(dethread call(i)
(setq l (range 1 i 1))
(threadstore "tobecleared" l)
)
(call 10)
(call 100)
(call 20)
(wait)
(println (threadretrieve "tobecleared"))
; we clear the namespace: "tobecleared"
(threadclear "tobecleared")
trace: (bool trace)
Activates the trace during execution: (trace true)
type: (type e)
Returns the type of its argument
unique: (unique lst)
Remove the duplicates in lst. The comparison is done with: ==
use: (use bib)
Loads a dynamic library whose path is given by the environment variable: LISPEPATH.
trigger: (trigger key)
Wake up all threads waiting on key.
wait: wait for threads to end
This instruction allows you to wait for all threads to finish. See dethread for an example.
waiton: (waiton key)
Put a thread on hold until it is woken up with trigger on that key.
while: (while (condition) instruction1 instruction2 ...)
Allows looping as long as a condition is true.
(setq v 10)
(while (v > 0) (setq v ( v 1))
xor: or Boolean exclusive
zerop: checks if a value is zero
Functions inspired by Haskell
Important: The methods: map, filter, take, repeat, cycle, takewhile, drop, dropwhile, fold, scan are automatically composed one with the others, unless you use the ?
non composing operator.
(map '+ (map '* '(1 2 3)))
; is actually transformed into one single loop,
; which takes the following form:
(setq #recipient1 ())
(loop #i1 (quote (1 2 3))
(setq #accu1 (+ (* #i1 #i1) (* #i1 #i1)))
(push #recipient1 #accu1)
)
; in this case, the first map is not composed with the inner map
; because of the '?'
(?map '+ (map '* '(1 2 3))
(setq #recipient3 ())
(loop #i3
(setq #recipient2 ())
(loop #i2 (quote (1 2 3))
(setq #accu2 (* #i2 #i2))
(push #recipient2 #accu2)
)
(setq #accu3 (+ #i3 #i3))
(push #recipient3 #accu3)
)
Hence, when a sequence of calls to these methods is made, the system automatically factorizes them into one single loop, unless the ?
operator is applied to one of the instructions.
Hence, thanks to that implementation, it is possible to perform lazy evaluations
Note On Composition
If you want to know how your different functions have been composed, the easiest way is to store them in a function and to display the content of that function.
(defun tst(x) (map '* (map '+ x)))
; Displaying the content of 'tst'
(defun tst (x)
(#compose (1 0)
(setq #recipient1 ())
(loop #i1 (quote (1 2 3))
(setq #accu1 (+ (* #i1 #i1) (* #i1 #i1)))
(push #recipient1 #accu1)
)
)
)
for: (for x list action)
Applies action to each element from list and yields a list out of the results.
(for i '(1 2 3 4) (* i i)) ; (1 4 9 16)
map: (map op list)
Applies an operation to each item in a list
(map '+ '(1 2 3)) returns (2 4 6)
(map '(+ 1) '(1 2 3)) returns (2 3 4)
; important, we interpret (1 ) as ( x 1)
(map '(1 ) '(1 2 3)) returns (0 1 2)
; Important, we interpret ( 1) as ( 1 x)
(map '( 1) '(1 2 3)) returns (0 1 2)
(map (lambda (x) (+ x 1)) '(1 2 3)) returns (2 3 4)
;An amusing example, we execute a shell command
!v=ls
; But 'v' contains strings ending in carriage return.
; This is how you can initialize all the strings at once.
(setq v (map 'trim v))
filter: (filter condition list)
Filters the items in a list. The condition can be a lambda.
(filter '(< 10) '(1 4 5 10 11 20)) returns (1 4 5)
(filter (lambda (x) (< x 10)) '(1 4 5 10 11 20)) returns (1 4 5)
drop: (drop nb list)
Drops nb elements from a list and returns the remainder.
dropwhile: (dropwhile condition list)
Skips all items meeting the condition, then returns the rest.
(dropwhile '( < 10) '(1 3 5 9 10 3 4 12)) returns (10 3 4 12)
take: (take nb list)
Take nb elements from a list.
replicate: (replicate nb value)
Create a list, in which value is repeated nb times.
(replicate 4 '(1 2)) ; yields ((1 2) (1 2) (1 2) (1 2))
repeat: (repeat value)
Create a list, in which value is stored over and over again. It should be associated with a take for instance.
(take 10 (repeat 5)) ; yields: (5 5 5 5 5 5 5 5 5 5)
cycle: (cycle list)
Create a list, in which we cycle through liste to store in. It should be associated with a take for instance.
(take 10 (cycle '(1 2 3)) ; yields: (1 2 3 1 2 3 1 2 3 1)
takewhile: (takewhile condition list)
Keeps all the elements satisfying the condition and then removes the rest.
(takewhile '( < 10) '(1 3 5 9 10 3 4 12))) ; returns (1 3 5 9)
irange: (irange initial increment)
Infinite range, starting at initial by increment step.
(takewhile '(< 10) (irange 1 2)) ; yields: (1 3 5 7 9)
(takewhile '(< 100) (map '* (irange 1 2))) ; yields: (1 9 25 49 81)
(irange initial bound increment)
This specific irange is used to avoid creating a list of integers beforehand in a loop with range. It implements an incrementbased loop.
(loop i (irange 0 100 1)
(println i)
)
foldl: (foldl op initial list)
applies an operation on a list, providing an initial value from the beginning of the list
(foldl ' 10 '(1 2 3)) ; gives 4
foldl1: (foldl1 op list)
Same as foldl but takes the first item in the list as first value
(foldl1 ' '(1 2 3)) ; gives 4
foldr: (foldr op initial list)
as foldl but starts from the end of the list
foldr1: (foldr1 op list)
as foldl1 but starts from the end of the list
scanl: (scanl op initial list)
Keeps the list of intermediate items in a list
(scanl ' 10 '(20 30 40)) ; gives (10 10 40 80)
scanl1: (scanl1 op list)
Same thing, but we use the first element of the list for the calculation.
(scanl1 ' '(20 30 40)) ; gives (20 10 50)
scanr: (scanr op initial list)
We start from the end of the list for the accumulation
(scanr '+ 0 '(3 5 2 1)) ; gives (11 8 3 1 0)
scanr1: (scanr1 op list)
We start from the end of the list for the accumulation and use the last item for the operations
zip: (zip l1 l2 l3...)
Allows to make a list from the list elements given as arguments.
(zip '(1 2 3) '(4 5 6) '(7 8 9)) ; gives ((1 4 7) (2 5 8) (3 6 9))
zipwith: (zipwith op l1 l2 l3...)
Allows to apply an operator between list items.
(zipwith '+ '(1 2 3) '(4 5 6) '(7 8 9)) ; yields (12 15 18)
Non Composition Operator: an example
The non composition operator: !
prevents LispE from combining two structures:
; We let LispE compose the following expression.
; At each step it processes both the scanl1 and the map
(map '* (scanl1 '+ '(10 20 30))) ; result is (10 900 864900)
; We prevent LispE from composing in the following expression:
(!map '* (scanl1 '+ '(10 20 30))) ; result is (100 900 3600)
Lambdas With: scan/fold
There are two different sorts of scan/fold functions:
 from the left (indicated with an
l
at the end of the function name)  from the right (indicated with an
r
at the end of the function name)
These two sorts of function not only process lists in a reverse order, they also compute their values in a reverse order.
Compare for instance:
(foldl1 ' '(1 2 3)) ; yields 4
(foldr1 ' '(1 2 3)) ; yields 2
If you use a lambda function then this lambda must take two arguments, but the order of the arguments depends on the type of functions.
 left function, the accumulator is the first argument
 right function, the accumulator is the second argument
; left function, the accumulator is the first argument
(scanl1 (lambda (accu x) (+ accu x 1)) '(1 2 3))
; right function, the accumulator is the second argument
(scanr1 (lambda (x accu) (+ accu x 1)) '(1 2 3))
Operators à la APL
We have implemented some operators, which draw their inspiration from APL
transpose: ⍉
This method transposes a matrix row/column.
(rho 3 4 (iota 5)) ; is ((1 2 3 4) (5 1 2 3) (4 5 1 2))
(transpose (rho 3 4 (iota 5))) ; yields ((1 5 4) (2 1 5) (3 2 1) (4 3 2))
; you can also use the operator: ⍉
(⍉ (rho 3 4 (iota 5))) ; yields ((1 5 4) (2 1 5) (3 2 1) (4 3 2))
scan: \\
 (\\ 'op list) : applies a function to the list two elements by two elements
 (\\ 'integers list) either extend nb times the corresponding element. When the value in integers is 0 add 0 to the list.
; apply an operator
(\\ '+ '(1 2 3)) ; yields (1 3 6) [1 (1+2) ((1+2)+3)
(\\ '(2 0 3) '(45 26)) ; yields (45 45 0 26 26 26)
; You can also use the actual name
(scan '+ '(1 2 3)) ; yields (1 3 6) [1 (1+2) ((1+2)+3)
backscan: ⍀ or \\
 (\\ 'op list) : applies a function to the list two elements by two elements from the end
 (\\ 'boolean_list list) either keep the corresponding element or add a zero from the end
; apply an operator
(\\ ' '(1 2 3)) ; yields (1 1 4)
(\\ ' '(1 2 3)) ; yields (3 1 0)
; You can also use the actual name
(backscan ' '(1 2 3)) ; yields (3 1 0)
; or
(⍀ ' '(1 2 3)) ; yields (3 1 0)
reduce: //
 (// list) : duplicates the list
 (// 'op list): applies a function between each element of the list
 (// integers list): extend the list according to the list of integers
(// '+ '(1 2 3)) ; yields 6
(// '(1 0 2) '(1 2 3)) ; yields (1 3 3)
; You can also use the alphabetical name
(reduce '+ '(1 2 3)) ; yields 6
backreduce: ⌿ or //
 (// list) : reverse the list
 (// 'op list): applies a function between each element of the list, from the end
 (// boolean_list list): keeps only the element for which a 1 is provided, from the end
(// ' '(1 2 3)) ; yields 4 : 123
(// ' '(1 2 3)) ; yields 0 : 321
; You can also use the alphabetical name
(backreduce '+ '(1 2 3)) ; yields 6
; or
(⌿ + '(1 2 3))
iota, iota0 (⍳, ⍳0): list of consecutive numerical values
 (iota n) :returns a list of numerical values starting at 1 up to n included
 (iota0 n) :returns a list of numerical values starting at 0 up to n excluded
You can also put more than one n in iota:
iota n n' n"...: returns a list of nb lists of n, n' and n'' elements
Note that if your seed value is a decimal value, then the list will be a list of numbers, otherwise it will be a list of integers.
(iota 10) ; yields (1 2 3 4 5 6 7 8 9 10)
(iota0 10) ; yields (0 1 2 3 4 5 6 7 8 9)
; If your value seed value is a decimal number, then the list will be a list of numbers
(iota 10.1) ; yields (1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1)
(iota0 10.1) ; yields (0.1 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1)
; We can also use the corresponding Greek letter
(⍳ 3 4) ; yields ( (1 2 3) (1 2 3 4) )
rho (⍴): size
rho can be used in three different ways:
 (rho list): it returns the size of the list. If the list is a matrix, it returns its two dimensions
 (rho sz list): builds a list of size sz out of list
 (rho sz1 sz2 list): builds a matrix of dimension sz1,sz2 out of list
(rho (iota 2 2)) ; yields (2 2)
(rho 10 (iota 3)) ; yields (1 2 3 1 2 3 1 2 3 1)
; We can also use the corresponding Greek letter
(⍴ 3 3 (iota 4)) ; yields ((1 2 3) (4 1 2) (3 4 1))
; rho can also be used to create a linked list.
; If the input list is a linked list
; The list is then built backwards
(rho 2 3 (llist 1 2 3)); ((3 2 1) (3 2 1))
; The same for lists
(rho 2 3 (list 1 2 3)); ((1 2 3) (1 2 3))
° : outer product
This involves two data items and a function. The function can be any dyadic function, including userdefined functions. The function operates on pairs of elements, one taken from the left argument and one from the right, till every possible combination of two elements has been used.
(° '(2 3 4) '* '(1 2 3 4))
; Multiplies every number in X by every
; number in Y generating a multiplication
; table
((2 4 6 8) (3 6 9 12) (4 8 12 16))
.: inner product
Inner product takes the form:
(. DATA1 FN1 FN2 DATA2)
Where the operands, FN1 and FN2, are both dyadic functions, including userdefined functions. Inner product first combines the data along the last axis of the left argument with the data along the first axis of the right argument in an 'Outer Product' operation with the right operand. Finally a 'reduction' operation is applied to each element of the result.
If the two arguments are vectors of the same size, then the inner product gives the same result as FN2 being applied to the data and then FN1 being applied to the result in a reduction operation.
(. '(1 2 3) '+ '* '(4 5 6)); yields 32
When applied to data of more than one dimension, such as matrices, the operation is more complex. For matrix arguments the shape of the result of the operation is given by deleting the two inner axes and joining the others in order. For example if we have:
TABA of 4 rows and columns
and TABB of 5 rows and 6 columns The inner dimensions are used by the inner product operation, and the result will be a 4row 6column matrix.
The operations take place between the rows and columns of the two matrices and are therefore the same as inner product operations between vectors as described above.
TABLE1 TABLE2
1 2 6 2 3 4
5 4 7 0 1 8
3 0
Which we can write with the inner product as:
(. '((1 2) (5 4) (3 0)) '+ '* '((6 2 3 4) (7 0 1 8)))
; which yields:
((20 2 5 20) (58 10 19 52) (18 6 9 12))
== : numerical Boolean
This operator returns either 0 or 1 for a comparison between two values. If the comparison is done with lists, then it returns a list with 1 and 0 where values are the same.
Note that if you use the operator =
in a à la APL instruction, it will be replaced with ==
.
(== '(1 2 3) '(1 5 3)) ; yields (1 0 1)
; Here the = is automatically replaced with == in order to return numerical Boolean value
(° (iota 3) '= (iota 3)) ; yields ((1 0 0) (0 1 0) (0 0 1))
, : concatenate operator

As a monadic operator, it actually works as flatten.

As a dyadic operator, it concatenates lists together
(, (iota 3 3)) ; yields (1 2 3 1 2 3)
(, (iota 4) 5) ; yields ((1 5) (2 5) (3 5) (4 5))
(, (iota 2 2) (iota 2 2)) ; yields ((1 2 1 2) (1 2 1 2))
∈: (member m values)
This operator scans a container for elements that are part of the values list. It then returns a container, in which the elements that are part of values are set to 1 or 0 else.
(setq m (rho 3 3 (iota 9))) ; m is ((1 2 3) (4 5 6) (7 8 9))
(setq r (∈ m '(1 3 4))) ; r is ((1 0 1) (1 0 0) (0 0 0))
⍤: (rank m D1 D2...)
This operator applies to matrices and tensors. It returns a submatrix corresponding to the provided coordinates. Replacing a dimension with 1 skips it in the final matrix or in the final tensor. In this case, LispE returns a specific axe from the tensor object.
(setq m (rho 3 4 5 (iota 60)))
;(((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15) (16 17 18 19 20))
; ((21 22 23 24 25) (26 27 28 29 30) (31 32 33 34 35) (36 37 38 39 40))
; ((41 42 43 44 45) (46 47 48 49 50) (51 52 53 54 55) (56 57 58 59 60)))
(rank m 1) ; yields ((21 22 23 24 25) (26 27 28 29 30) (31 32 33 34 35) (36 37 38 39 40))
(rank m 1 1) ; (26 27 28 29 30)
(rank m 1 1) ; yields ((6 7 8 9 10) (26 27 28 29 30) (46 47 48 49 50))
(rank m 1 1 1) ; yields ((2 7 12 17) (22 27 32 37) (42 47 52 57))
(irank D1 D2...)
This function gives the same result as rank. It should be used to loop across different dimensions
(setq m (rho 3 4 5 (iota 60)))
(loop d (irank m 1 1) (print d))
; Displays:
;((1 6 11 16) (21 26 31 36) (41 46 51 56))
;((2 7 12 17) (22 27 32 37) (42 47 52 57))
;((3 8 13 18) (23 28 33 38) (43 48 53 58))
;((4 9 14 19) (24 29 34 39) (44 49 54 59))
;((5 10 15 20) (25 30 35 40) (45 50 55 60))
(determinant m)
Computes the matrix determinant of a square matrix m
(ludcmp m)
ludcmp applies to a matrix and returns a list of indexes. ludcmp replaces a real nbyn matrix, m, with the LU decomposition of a rowwise permutation of itself. Important: the matrix is modified by the process.
(setq m (rho 2 2 (iota 4)))
(setq idx (ludcmp m))
; idx is (1 1) and m is now: ((3 4) (0.333333 0.666667))
(lubksb m idx y)
Solves the set of n linear equations mx = y
. (lubksb must be used with the procedure ludcmp to do this.)
y is optional. When y is not provided, then by default it will be the identity matrix, and it will act as a matrix inversion.
(setq m (rho 2 2 (iota 4)))
(setq idx (ludcmp m)) ; m is modified
(setq y (lubksb m idx)) ; here the matrix is inverted
(setq m (matrix '((1 9 8) (2 3 4) (12 21 34))))
(setq y (matrix '((1 2 3) (4 5 6) (7 8 9))))
(setq idx (ludcmp m))
(setq x (lubksb m idx y)) ; here we solve the linear equations
⌹: (invert m), (solve w y)
 invert provides the inversion of a matrix.
 solve provides a way to solve linear equations such as: W×X = Y. It returns X. "×" is the matrix multiplication.
The inversion and the solver are based on a LUDCMP decomposition followed with a LUBKSB decomposition. Basically, inverting a matrix is to solve linear equations where Y is the identity matrix.
(invert (rho 2 2 (iota 4))) ; yields ((2 1) (1.5 0.5))
(setq w (matrix '((1 9 8) (2 3 4) (12 21 34))))
(setq y (matrix '((1 2 3) (4 5 6) (7 8 9))))
(setq x (solve w y))
; yields x is ((3.94737 4.89474 5.84211) (1.61404 2.22807 2.84211) (2.18421 2.86842 3.55263))
(. w + * x) ; yields ((1 2 3) (4 5 6) (7 8 9))
System
(command (cmd) Executes a system command and returns the result as a list)
(setenv (name value) Creates or modifies an environment variable)
(getenv (name) Retrieves the value of an environment variable)
(fileinfo (path) Returns information about a file)
(realpath (path) Returns the full path corresponding to a partial path)
(ls (path) returns the contents of a directory)
(isdirectory (path) checks if 'path' is a directory)
Date and Chrono
; Chrono
(chrono) : creates a chrono object
; Date methods
(date) Initializes a 'date' object.
(year (date (d 1)) year(int d): returns the year (d = 1) or modifies it)
(month (date (d 1)) month(int d): returns the month (d = 1) or modifies it)
(day (date (d 1)) day(int d): returns the day (d = 1) or changes it)
(hour (date (d 1)) hour(int d): returns the time (d = 1) or changes it)
(minute (date (d 1)) minute(int d): returns the minute (d = 1) or changes it)
(second (date (d 1)) second(int d): returns the second (d = 1) or modifies it)
(setdate(y (m 1) (d 1) (H 1) (M 1) (S 1)) setdate(y,m,d,H,M,S): Creates a date from its compasantes (1 for the default value))
(yearday (date) yearday(): returns the number of the day in the year)
(weekday (date) weekday(): returns the day of the week)
Examples
; Using dates
(setq d (date))
(println "Year:" (year d))
; We initialise a first chrono value
(setq beginning (chrono))
; ... We do some stuff here
(setq end (chrono))
(println "The stuff took:" ( end beginning) "ms")
Files
; File methods
(file (path (mode (quote r))) Open a file with 'pathname' and action == 'r'w'a)
(file_close (stream) Close a file)
(file_read (stream (nb 1)) Read the whole file at once or nb characters)
(file_readline (stream) Read one line from the file)
(file_readlist (stream) Read the whole file and store each line in a list)
(file_getchar (stream) Read one UTF8 character at a time)
(file_write (stream str) Write a string to a file)
(file_eof (stream) Check if a file reached 'end of file')
Examples
; Files
; We open a file for reading
(setq r (file "myfile.txt" 'r))
; We read one line
(println (file_getline r))
; we close our file
(file_close r)
; We write in a file
(setq w (file "myfile.txt" 'w))
(file_write w "my test")
(file_close w)
Strings
(trim0 (str) remove '0' at the end of the string)
(trim (str) Cuts all 'space' characters)
(trimleft (str) Trim all 'space' characters to the left)
(trimright (str) Cuts all 'space' characters to the right)
(vowelp (str) Checks if the string only contains vowels)
(consonantp (str) Checks if the string only contains consonants)
(lowerp (str) Checks if the string is only lowercase)
(upperp (str) Checks if the string is only capitalized)
(alphap (str) Checks if the string contains only alphabetic characters)
(punctuationp (str) Checks if the string contains only punctuation)
(lower (str) puts in lower case)
(upper (str) is capitalized)
(deaccentuate (str) Replaces accented letters with their nonaccented form)
(replace (str fnd rep (index)) Replaces all substrings from index (default value is 0)
(format str e1 e2 ... e9) str must contains variables of the form: %I,
where 1 <= i <= 9, which will be replaced with their corresponding element.
Ex. (format "It is a %1 %2" "nice" "car") ; yields It is a nice car
(convert_in_base value base (convert_from) Converts a value into a different base or from a value in different base
Ex.
(convert_in_base 36 2) ; yields 100100
(convert_in_base "100100" 2 true) ; yields 36, in this case the initial value is in base 2
(left (str nb) Returns the 'n' characters on the left)
(right (str nb) Returns the last 'n' characters on the right)
(middle (str pos nb) Returns the 'n' characters from the 'p' position)
(split (str fnd) Splits the string into substrings according to a given string)
(splite (str fnd) Same as split but keeps the empty strings)
(tokenize (str) Splits the string into a list of tokens)
(tokenizee (str) same as 'tokenize' but keeps the blanks)
(ngrams (str nb)) Builds a lists of ngrams of size nb
(ord (str) Returns the Unicode codes of each character of 'str')
(chr (nb) Returns the Unicode character corresponding to the code 'nb')
(fill c nb Returns a string, which contains the string 'c' 'nb' times)
(padding str c nb Pads the string str with c string up to nb characters)
(editdistance str strbis Computes the edit distance between str and strobes)
Rule Tokenization
LispE also provides another mechanism to handle tokenisation. In this case, we use a set of predefined rules that can be modified.
; Tokenization with rules
(tokenizer_rules () Create a 'rules' object for tokenisation)
(tokenize_rules (rules str) Applies a 'rule' object to a string to tokenize it)
(get_tokenizer_rules (rules) Gets the underlying tokenizer rules)
(set_tokenizer_rules (rules lst) Stores a new set of rules)
Here is an example:
; We need first a rule tokenizer object
(setq rules (tokenizer_rules))
; which we apply to a string
(tokenize_rules rules "The lady, who lives here, bought this picture in 2000 for $345.5")
; ("The" "lady" "," "who" "lives" "here" "," "bought" "this" "picture" "in" "2000" "for" "$" "345.5")
This underlying set of rules can be loaded and modified to change or enrich the tokenization process, thanks to tokenizer_rules.
(setq rules (tokenizer_rules))
(setq rules_list (get_tokenizer_rules rules)
The rules are applied according to a simple algorithm. First, rules are automatically identified as:
 character rules: the rule starts with a specific character
 entity rules: the rule starts with an entity such as: %a, %d etc...
 metarules: the rule pattern is associated with an id that is used in other rules.
IMPORTANT
 The rules should always be ordered with character rules first and ends with entity rules.
 The most specific rules should precede the most general ones.
Metarules
A metarule is composed of two parts:
 c:expression, where c is the metacharacter that is accessed through %c and expression is a single body rule. for instance, we could have encoded %o as: "o:[≠ ∨ ∧ ÷ × 2 3 ¬]"
IMPORTANT:
These rules should be declared with one single operation. Their body will replace the call to a %c in other rules (see the test on metas in the parse section) If you use a character that is already a metacharacter (such as "a" or "d"), then the metacharacter will be replaced with this new description...
However, its content might still use the standard declaration:
"1:{%a %d %p}": "%1 is a combination of alphabetical characters, digits and punctuations
Formalism
A rule is composed of two parts: body=action
.
N.B The action is not used for the moment, but is required. It can be a number or a '#'.
body uses the following instructions:
 x is a character that should be recognized
 #xy interval between ascii characters x and y
 (..) is a sequence of optional instructions
 [..] is a disjunction of possible characters
 {..} is a disjunction of metacharacters
 x+ means that the instruction can be repeated at least once
 x means that the character should be recognized but not stored in the parsing string
 %.~.. means that all character will be recognized except for those in the list after the tilde.
 %x is a metacharacter with the following possibilities:
 %. is any character
 %a is any alphabetical character (including unicode ones such as éè)
 %C is any uppercase character o %c is any lowercase character o %d is any digits
 %H is any hangul character
 %n is a nonbreaking space
 %o is any operators
 %p is any punctuations
 %r is a carriage return both \n and \r o %s isaspace(32)oratab(09)
 %S is both a carriage return or a space (%s or %r)
 %? is any character with the possibility of escaping characters with a '' such as: \r \t \n or "
 %nn you can create new metarules associated with any characters...
IMPORTANT: do not add any spaces as they would be considered as a character to test...
; A metarule for hexadecimal characters
; It can be a digit, ABCDEF or abcdef
1:{%d #AF #af}
; This is a basic rule to handle regular characters
!=0
(=0
)=0
[=0
]=0
; This rule detects a comment that starts with //
; any characters up to a carriage return
//%.~%r+=#
; These rules detects a number
; Hexadecimal starting with 0x
0x%1+(.%1+)([p P]([ +])%d+)=3
; regular number
%d+(.%d+)([e E]([ +])%d+)=3
JSON Instructions
(json (element) Returns the element as a JSON string)
(json_parse (str) Compile a JSON string)
(json_read (filename) Reads a JSON file)
Regular Expressions
LispE provides different means of regular expressions, both traditional (e.g. posix) and designed for LispE specifically.
Posix Regular Expressions
(deflib prgx (exp (str)) Creates a posix regular expression from a string)
(deflib prgx_find (exp str (pos 0)) Searches in 'str' for the substring that matches the posix regular expression from 'pos'.)
(deflib prgx_findall (exp str (pos 0)) Searches in 'str' all the substrings that matches the posix regular expression)
(deflib prgx_find_i (exp str (pos 0)) Returns the positions in 'str' of the substring that matches the regular expression from 'pos')
(deflib prgx_findall_i (exp str (pos 0)) Returns the positions in 'str' of all the substrings that matches the regular expression.)
(deflib prgx_match (exp str) Checks that 'str' matches the posix regular expression)
(deflib prgx_replace (exp str rep) Replaces 'str' by 'rep' via a posix regular expression)
(deflib prgx_split (exp str) Split 'str' via a posix regular expression)
Examples
; We create our regular expression
; It is preferable to use the low accent (backquote) to avoid having to double the \
(setq r (prgx `\w+`))
true
; We're checking to see if it's a match
(prgx_match r "ABCD")
true
; We are looking for the first matching string.
(prgx_find r "This is a test: 123A here")
This
; We're looking for all occurrences
(prgx_findall r "This is a test: 123A and 45T and 67U here")
("This" "is" "a" "test" "123A" "and" "45T" "and" "67U" "here")
Regular Expressions
(deflib rgx (exp (str)) Create a regular expression from a string)
(deflib rgx_find (exp str (pos 0)) Searches in 'str' the substring that matches the regular expression from 'pos')
(deflib rgx_findall (exp str (pos 0)) Searches in 'str' all the substrings that matches the regular expression.)
(deflib rgx_find_i (exp str (pos 0)) Returns the positions in 'str' of the substring that matches the regular expression from 'pos')
(deflib rgx_findall_i (exp str (pos 0)) Returns the positions in 'str' of all the substrings that matches the regular expression.)
(deflib rgx_match (exp str) Checks that 'str' matches the regular expression)
(deflib rgx_replace (exp str rep) Replaces 'str' by 'rep' via a regular expression)
(deflib rgx_split (exp str) Split 'str' via a regular expression)
Description of regular expressions
 %d is any number
 %x is a hexadecimal digit (abcdef0123456789ABCDEF)
 %p represents any punctuation
 %c represents any lowercase letter
 %C is any uppercase letter
 %a represents any letter
 ? represents any character
 %? is the character "?" itself
 %% is the "%" character itself
 %s represents any space character, including unbreakable space.
 %r is the carriage return
 %n represents an unbreakable space
 ~ negation
 \x escape character
 \ddd character code on 3 integers.
 \xFFFF character code of 4 hexas exactly
 {...} character disjunction
 character sequence
 {az} between a and z included
 ^ the expression must start at the beginning of the string
 $ the expression must match to the end of the string
Examples :
 dog%c corresponds to dogs or dogg
 m%d corresponds to m0, m1,...,m9
 {%dab} corresponds to 1, a, 2, b
 {%dab}+ corresponds to 1111a, a22a90ab
Examples
; We create our regular expression
(setq r (rgx "%d+%C"))
true
; We're checking to see if it's a match
(rgx_match r "123A")
true
; We are looking for the first matching string.
(rgx_find r "This is a test: 123A here")
123A
; We're looking for all occurrences
(rgx_findall r "This is a test: 123A and 45T and 67U here")
("123A" "45T" "67U")
Math
(fabs (val) calculates the absolute value of a float type number)
(acos (val) calculates the arc cosine)
(acosh (val) calculates the hyperbolic arc cosine)
(asin (val) calculates the sine arc)
(asinh (val) calculates the hyperbolic sine arc)
(atan (val) calculates the tangent arc)
(atanh (val) calculates the hyperbolic arc tangent)
(cbrt (val) calculates the cubic root)
(cos (val) calculates the cosine)
(cosh (val) calculates the hyperbolic cosine)
(erf (val) calculates the error function)
(erfc (val) calculates the complementary error function)
(exp (val) returns e high to the requested power)
(exp2 (val) returns 2 high to the requested power)
(expm1 (val) returns high e to the requested power minus 1)
(floor (val) returns the nearest lower integer)
(lgamma (val) calculates the natural logarithm of the absolute value of the gamma function)
(log (val) calculates the natural logarithm (in base e))
(log10 (val) calculates the logarithmic decimal (base 10))
(log1p (val) calculates the natural logarithm (in base e) of 1 plus the given number)
(log2 (val) calculates the binary logarithm (base 2))
(logb (val) extracts the exponent of a number)
(nearbyint (val) returns the nearest integer using the current rounding method)
(rint (val) returns the closest integer using the current rounding method with exception if the result is different)
(round (val) returns the nearest integer, following the rounding rules)
(sin (val) calculates the sinus)
(sinh (val) calculates the hyperbolic sinus)
(sqrt (val) calculates the square root)
(tan (val) calculates the tangent)
(tanh (val) calculates the hyperbolic tangent)
(tgamma (val) calculates the gamma function)
(trunc (val) returns the nearest integer whose absolute value is lower)
(radian (val) converts from degree into radian)
(degree (val) converts from radian into degree)
(gcd v1 v2) Greater Common Divison
(hcf v1 v2) Higher Common Factor
Random
(random (nb) returns a random value between 0 and nb)
(shuffle (list) randomly mixes items in a list)
(random_choice (nb list initial) returns a list of nb random values among the elements in 'list', and (initial/size list) > 1)
(uniform_distribution (nb (alpha 0) (beta 1)) Uniform discrete distribution)
(bernoulli_distribution (nb (alpha 0.5)) Bernoulli distribution)
(binomial_distribution (nb (alpha 1) (beta 0.5)) binomial distribution)
(negative_binomial_distribution (nb (alpha 1) (beta 0.5)) Negative binomial distribution)
(geometric_distribution (nb (alpha 0.5)) Geometric_distribution)
(fish_distribution (nb (alpha 1)) Fish_distribution (alpha = 1))
(exponential_distribution (nb alpha) Exponential distribution)
(gamma_distribution (nb alpha beta) Gamma distribution)
(poisson_distribution (nb (alpha 1) Poisson distribution)
(weibull_distribution (nb (alpha 1) (beta 1)) weibull distribution)
(extreme_value_distribution (nb (alpha 0) (beta 1)) Extreme Value distribution)
(normal_distribution (nb (alpha 0) (beta 1)) Normal distribution)
(lognormal_distribution (nb (alpha 0) (beta 1)) Lognormal_distribution)
(chi_squared_distribution (nb alpha) Chisquared distribution )
(cauchy_distribution (nb (alpha 0) (beta 1)) Cauchy distribution)
(fisher_distribution (nb (alpha 1) (beta 1)) Fisher Fdistribution)
(student_distribution (nb (alpha 1)) Student TDistribution)
(discrete_distribution (nb list) Discrete distribution)
(piecewise_constant_distribution (nb inter) Piecewise constant distribution )
(piecewise_linear_distribution (nb inter) Piecewise linear distribution )
Ontologies
An ontology is a defined as a set of concepts that can be combined one the other with the following operators:
 eq : compare two concepts together
 & : intersection of concepts
  : union of concepts
 ^ : exclusive union of concepts (same concepts are discarded)
 &~ : We keep only the concepts that the concepts does not have
 ~ : The set of all the concepts that are different from the current concept
Each ontology exposes by default the _absurd concept, which is the empty set.
Important : this ontology is by no way hierarchical, as in traditional ontologies. Concepts can be combined throughout the whole ontology, whatever their place or definition.
(ontology_absurd (h) Returns the '_absurd' concept for this ontology)
(ontology_find (h conc) Checks if a concept list has a name in the ontology)
(ontology_ontology (conc) Returns the ontology in which this concept is declared)
(ontology (name) Creates an ontology)
(ontology_list (conc) Returns the list of concepts stored in concepts)
(ontology_remove (conc a) Removes a concept from another concept definition in the ontology)
(ontology_add (conc a) Enriches the concept definition in the ontology with the other concept)
(ontology_intersect (conc a) Checks if two concepts have concepts in common)
(ontology_contain (large_conc conc) Check if large_conc contains conc)
(ontology_concept (h name) Returns the concept associated with this name)
(ontology_all (h) Returns the list of all concepts)
(ontology_absurdp (conc) Checks if the concept is '_absurd')
(ontology_create (h name (conc)) Creates a new concept definition with a name. The concept description can also be provided)
Example
; We create an ontology: colors
(setq h (ontology "colors"))
; Our top concept is: color
(setq color (ontology_create h "color"))
; different colors, which all share the concept color
(setq red (ontology_create h "red" color))
(setq green (ontology_create h "green" color))
(setq blue (ontology_create h "blue" color))
(setq violet (ontology_create h "violet" color))
(setq indigo (ontology_create h "indigo" color))
(setq yellow (ontology_create h "yellow" color))
(setq orange (ontology_create h "orange" color))
; We can also combine two color concepts together
(ontology_add violet (list color indigo))
(ontology_add yellow (list color indigo))
; we can intersect two concepts
(println (ontology_list (& violet yellow)))
(println (ontology_list ( violet yellow)))
; We can remove a concept from a concept definition
(ontology_remove violet color)
(println "Sans color:" (ontology_list violet))
; These two calls return the same value
(println (ontology_concept h "orange") orange)
; We create a color black by combining red, green and blue
(ontology_create h "black" ( red green blue))
(println (ontology_list (ontology_concept h "black")))
; We display all concepts in the ontology
(println (ontology_all h))
; We can compare concepts
(if (eq
(& red ( red green))
(ontology_concept h "red")
)
(println 'ok)
(println 'non)
)
; When an intersection is empty we return _absurd
(if (ontology_absurdp (& red green))
(println 'Oui)
(println 'Non)
)
; In this case yellow is just yellow
(ontology_remove yellow yellow)
Sockets
(socket_create (port nblients (hostname)) create a server if hostname is omitted then the local hostname is used)
(socket_connect (hostname port) connect to the server)
(socket_wait (sock) wait for a client to connect and returns its socket id)
(socket_read (sock (socketClientId 1)) read a string on a socket. On the server side 'socketClientId' is the value returned by 'wait()'. Use 'read()' on the client side)
(socket_write (sock str (socketClientId 1)) write the string s on the socket. On the server side num is the value returned by wait()'. Use 'write(s)' on the client side)
(socket_receive (sock nb (socketClientId 1)) read a string on a socket in a raw environment. On the server side 'socketClientId' is the value returned by 'wait()'. Use 'receive()' on the client side)
(socket_get (sock (socketClientId 1)) get one character from a socket in a non Tamgu environment. On the server side 'socketClientId' is the value returned by 'wait()'. Use 'get()' on the client side)
(socket_send (sock str (socketClientId 1)) write the string s on the socket in a non Tamgu environment. On the server side num is the value returned by wait()'. Use 'send(string s)' on the client side)
(socket_close (sock (socketClientId 1)) Close a socket. On the server side if 'socketClientId' is provided (it is the value returned by wait()) it closes the client socket otherwise it closes the current socket.)
(socket_blocking (sock flag) if 'flag' is true the socket works in 'blocking' mode otherwise in 'non blocking' mode)
(socket_settimeout (sock tm) Set a time out of 't' seconds on the socket)
(socket_gethostname (sock) return the current host name)
(socket_port (sock) return the current port number)
(socket_getpeername (sock socketClientId) return the current peer name)
Example of a server
; Creation of a server
(setq server (socket_create 2654 10))
(println (socket_gethostname server))
(println 'Waiting 'for 'a 'connection)
; We wait for a connection
(setq idclient (socket_wait server))
; We then read on this idclient
(println 'Reading (socket_read server idclient))
Example of a client
; we create a connection
; hostname is the name of the machine to which to connect
; as given by 'socket_gethostname' above
(setq client (socket_connect "hostname" 2654))
; We then write something on the socket
(socket_write client "This is a test")
GUI
LispE provides its own Graphical Library, which exposes the following instructions:
(deflib fltk_alert (widget msg) Pop up window to display an alert)
(deflib fltk_align (widget align) define the label alignment)
(deflib fltk_arc (widget x y w h a1 (a2)) Draw an arc / Add a series of points to the current path on the arc of a circle;)
(deflib fltk_ask (widget msg msg1 msg2 (msg3) (msg4)) Pop up window to pose a question)
(deflib fltk_backgroundcolor (widget (color)) set the background color)
(deflib fltk_bitmap (widget bitmap color (x) (y)) display a bitmap at position x,y in a window, or use the bitmap to fill in a button with type: FL_IMAGE_BUTTON_TYPE)
(deflib fltk_boundaries (widget low high) Define the boundaries of a slider)
(deflib fltk_button (widget x y w h label function (button_type) (button_shape) (object)) Create a button)
(deflib fltk_create_bitmap (bitmap length height) load a bitmap from a list of integers (bitmap) with dimensions)
(deflib fltk_create_gif (filename) load a GIF file)
(deflib fltk_circle (widget x y r (color)) Draw a circle. 'color' is optional.)
(deflib fltk_close (widget) close window)
(deflib fltk_coordinates (widget (x) (y) (w) (h)) return the coordinates of the window or set new coordinates)
(deflib fltk_create (x y w h label (function) (object)) Create a window)
(deflib fltk_create_resizable (x y label (function) (object)) Create a window)
(deflib fltk_drawcolor (widget (color)) set the color for the next drawings)
(deflib fltk_drawtext (widget txt x y) Put a text at position xy)
(deflib fltk_end (widget (timer)) Finalize the creation of a window a set an optional timer)
(deflib fltk_focus (widget) Get the focus)
(deflib fltk_gif (widget gif (x) (y) (wx) (wy)) display a GIF image in box at position x,y,wx,wy in a window, or use the image to fill in a button with type: FL_IMAGE_BUTTON_TYPE)
(deflib fltk_hide (widget) Hide the window)
(deflib fltk_input (widget x y w h label multiline (function) (object)) Creating an input object)
(deflib fltk_insert (widget val) Insert text in a widget value)
(deflib fltk_label (widget (label)) return the window label or set a new label to the window)
(deflib fltk_labelcolor (widget (color)) set or return the label color)
(deflib fltk_labelfont (widget (font)) set or return the label font)
(deflib fltk_labelsize (widget (sz)) set or return the label font size)
(deflib fltk_labeltype (widget (thetype)) set or return the label type)
(deflib fltk_line (widget x y x1 y1 (x2) (y2)) Draw a line between points x2 and y2 are optional)
(deflib fltk_lineshape (widget type_shape w) Select the line shape and its thikness)
(deflib fltk_loop (widget x y x1 y1 x2 y2 (x3) (y3)) Draw a series of lines x3 and y3 are optional)
(deflib fltk_multmatrix (widget a b c d x y) combine transformations)
(deflib fltk_on_close (widget function) This method sets a callback function to catch when the window is closing)
(deflib fltk_output (widget x y w h label multiline) Create an output widget)
(deflib fltk_pie (widget x y w h a1 a2) Draw a pie)
(deflib fltk_plot (widget points thickness (landmark)) Plot a graph from a table of successive xy points according to window size. If thickness===0 then points are continuously plotted else defines the diameter of the point. Return a which is used with plotcoords. The landmark is optional it is has the following structure: [XmaxWindow,YmaxWindow,XminValue,YminValue,XmaxValue,YmaxValue,incX,incY]. incX,incY are also optional.)
(deflib fltk_plotcoords (widget x y landmark) Compute the coordinates of a point(xy) according to the previous scale computed with plot. Returns a of two elements [xsys] corresponding to the screen coordinates in the current window.)
(deflib fltk_point (widget x y) Draw a pixel)
(deflib fltk_polygon (widget x y x1 y1 x2 y2 (x3) (y3)) Draw a polygon x3 and y3 are optional)
(deflib fltk_popclip (widget) Release a clip region)
(deflib fltk_pushclip (widget x y wx wy) Insert a clip region with the following coordinates)
(deflib fltk_rectangle (widget x y wx hy (color)) Draw a rectangle with optional color c)
(deflib fltk_rectanglefill (widget x y wx hy (color)) Fill a rectangle with optional color c)
(deflib fltk_redraw (widget) Redraw the window)
(deflib fltk_resize (widget minw minh maxw maxh) resize a window)
(deflib fltk_rgbcolor (widget r g b) return the value of rgb values combined)
(deflib fltk_rotate (widget d) rotate of d degrees the current transformation)
(deflib fltk_rotation (widget x y distance angle (draw)) Compute the coordinate of a rotated point from point x,y using a distance and an angle in radian. Return a vector of floats with the new coordinates.)
(deflib fltk_run (widget) Launch the GUI)
(deflib fltk_scale (widget x (y)) Scale the current transformation)
(deflib fltk_selection (widget pos nb) Selection in a widget value)
(deflib fltk_selection_color (widget (color)) Color for the selected elements)
(deflib fltk_show (widget) Show the window)
(deflib fltk_slider (widget x y w h label slider_orientation slider_value_type function (object)) Create a slider)
(deflib fltk_step (widget stp) Define the step in a slider)
(deflib fltk_textfont (widget f sz) Set a font with a size)
(deflib fltk_textsize (widget text) Return a map with w and h as key to denote width and height of the string in pixels)
(deflib fltk_transform_dx (widget x y) Transform a distance DX using the current transformation matrix.)
(deflib fltk_transform_dy (widget x y) Transform a distance DY using the current transformation matrix.)
(deflib fltk_transform_vertex (widget x y) Add transformations to vertices list.)
(deflib fltk_transform_x (widget x y) Transform a coordinate X using the current transformation matrix)
(deflib fltk_transform_y (widget x y) Transform a coordinate Y using the current transformation matrix)
(deflib fltk_translate (widget x y) translate the current transformation)
(deflib fltk_value (widget (val)) Set or return the widget value)
(deflib fltk_wrap (widget mode) Set wrap mode for a widget)
Predefined Values
; Couleurs
FL_FOREGROUND_COLOR
FL_BACKGROUND2_COLOR
FL_BACKGROUND_COLOR
FL_INACTIVE_COLOR
FL_SELECTION_COLOR
FL_GRAY0
FL_DARK3
FL_DARK2
FL_DARK1
FL_LIGHT1
FL_LIGHT2
FL_LIGHT3
FL_BLACK
FL_RED
FL_GREEN
FL_YELLOW
FL_BLUE
FL_MAGENTA
FL_CYAN
FL_DARK_RED
FL_DARK_GREEN
FL_DARK_YELLOW
FL_DARK_BLUE
FL_DARK_MAGENTA
FL_DARK_CYAN
FL_WHITE
; Forme des lignes
FL_SOLID
FL_DASH
FL_DOT
FL_DASHDOT
FL_DASHDOTDOT
FL_CAP_FLAT
FL_CAP_ROUND
FL_CAP_SQUARE
FL_JOIN_MITER
FL_JOIN_ROUND
FL_JOIN_BEVEL
; Position Slider
FL_VERT_SLIDER
FL_HOR_SLIDER
FL_VERT_FILL_SLIDER
FL_HOR_FILL_SLIDER
FL_VERT_NICE_SLIDER
FL_HOR_NICE_SLIDER
; Police de caractères
FL_HELVETICA
FL_HELVETICA_BOLD
FL_HELVETICA_ITALIC
FL_HELVETICA_BOLD_ITALIC
FL_COURIER
FL_COURIER_BOLD
FL_COURIER_ITALIC
FL_COURIER_BOLD_ITALIC
FL_TIMES
FL_TIMES_BOLD
FL_TIMES_ITALIC
FL_TIMES_BOLD_ITALIC
FL_SYMBOL
FL_SCREEN
FL_SCREEN_BOLD
FL_ZAPF_DINGBATS
FL_FREE_FONT
FL_BOLD
FL_ITALIC
FL_BOLD_ITALIC
; Type de bouton
FL_REGULAR_BUTTON_TYPE
FL_CHECK_BUTTON_TYPE
FL_LIGHT_BUTTON_TYPE
FL_REPEAT_BUTTON_TYPE
FL_RETURN_BUTTON_TYPE
FL_ROUND_BUTTON_TYPE
FL_IMAGE_BUTTON_TYPE
; Forme de bouton
FL_NORMAL_BUTTON_SHAPE
FL_TOGGLE_BUTTON_SHAPE
FL_RADIO_BUTTON_SHAPE
FL_HIDDEN_BUTTON_SHAPE
; Alignement
FL_ALIGN_CENTER
FL_ALIGN_TOP
FL_ALIGN_BOTTOM
FL_ALIGN_LEFT
FL_ALIGN_RIGHT
FL_ALIGN_INSIDE
FL_ALIGN_TEXT_OVER_IMAGE
FL_ALIGN_IMAGE_OVER_TEXT
FL_ALIGN_CLIP
FL_ALIGN_WRAP
FL_ALIGN_IMAGE_NEXT_TO_TEXT
FL_ALIGN_TEXT_NEXT_TO_IMAGE
FL_ALIGN_IMAGE_BACKDROP
FL_ALIGN_TOP_LEFT
FL_ALIGN_TOP_RIGHT
FL_ALIGN_BOTTOM_LEFT
FL_ALIGN_BOTTOM_RIGHT
FL_ALIGN_LEFT_TOP
FL_ALIGN_RIGHT_TOP
FL_ALIGN_LEFT_BOTTOM
FL_ALIGN_RIGHT_BOTTOM
FL_ALIGN_NOWRAP
FL_ALIGN_POSITION_MASK
FL_ALIGN_IMAGE_MASK
Example
(use 'gui)
; callback function
(defun pushed(b o)
(printerrln "Pressed" (fltk_label b))
)
; We create a Window
(setq wnd (fltk_create 100 100 1000 1000 "Test"))
; We create a button, which is linked to the function: 'pushed'
(setq button (fltk_button wnd 50 50 100 100 "ok" 'pushed))
; We finalize
(fltk_end wnd)
; We run the event loop
(fltk_run wnd)