Library Reference

In the following, arguments with the '+' sign are those consumed upon reaction with the library atoms, while arguments with the '-' sign are those generated by the library API. The slash (/) notation is used to indicate the arity of atoms.

Note: the LMNtal API is under development and its specification is subject to change.

Library atom

atom.new(+F,+N,-A)
Creates a symbol atom with the functor F (specified as a string) N (< 128) arguments. If N>0, the first N-1 arguments are set to 0, while the last argument is connected to the binary atom 'some' connected to the created atom and A. For instance, A=atom.new("pq",3) creates A=some(pq(0,0)). If N=0, A=atom.new("pq",0) creates A=none and an independent atom 'pq'.
atom.new(+F, +L, -A)
Creates a symbol atom with the functor F (specified as a string) and the arguments in the list L and the final argument A. For instance, atom.new("pq",[X,Y,Z],A) creates A = pq(X,Y,Z).
atom.new(F, L)
Creates a symbol atom with the functor F (specified as a string) and the arguments in the list L. For instance, atom.new("pq",[X,Y,Z]) creates pq(X,Y,Z).
atom.functor(+A0,-F,-N,-A)
F is bound to the string representation of the functor of A0, N is bount to the arity of A0, and A is bound to A0 (for later use). Works only when A0 is a symbol atom.
atom.swap(+A0,+I,+NewAi,-OldAi,-A)
A is bound to the atom A0 whose Ith argument is changed to NewAi. The original Ith argument is bound to OldAi. Works only when A0 and OldAi are symbol atoms.

Libraty float

float.of_str(+S,-N)
N is bound to a floating-point number whose string representation is S.

Library integer

integer.rnd(+N,-H)
H is bound to a random number between 0 and N-1.
integer.srnd(+N)
Initialize the random number generator using N as the new seed of random numbers.
integer.of_str(+S,-N)
N is bound to an integer whose string representation is S.
integer.set(+A,+B,+G)
Assume $a[A] and $b[B] are of type int and $g[G] is of type ground. Then creates a multiset $g[$a], $g[$a+1], ..., $g[$b]. For example, n=integer.set(1,100) will be reduced to n=1, ..., n=100.

Library io

Input/output in SLIM is done through ports. An operation on a port will return a new port to be used exactly once for future operations on the port.

For instance, the "Hello, World!" program can be written as:

io.print_line(io.stdout,"Hello, World!",io.free_port).

and a program that prints a single line from the standard input can be written as:

io.print_line(io.stdout,io.read_line(io.stdin,io.free_port),io.free_port).

A program that copies stdin to stdout can be written as:

main.
main :-
  io.read_token(io.stdin, I, S),
  loop(S, eof, I, io.stdout).
        
loop(S, EOF, I, O) :- S == EOF |
  io.free_port(I), io.free_port(O).
loop(S0, EOF, I0, O0) :- S0 \== EOF | 
  io.print_line(O0, S0, O),
  io.read_token(I0, I, S),
  loop(S, EOF, I, O).
io.stdin(-RetRort)
Returns a standard input port.
io.stdout(-RetRort)
Returns a standard output port.
io.stderr(-RetRort)
Returns a standard error port.
io.read_byte(+Port,-RetRort,-N)
Read a character from the input port Port and returns its code N and a new port RetRort. Returns -1 instead of N if the end of file is encountered.
io.read_char(+Port,-RetRort,-C)
Read a character C from the input port Port and returns it as a unary atom with the name C a new port RetRort. Returns a unary atom 'eof' if the end of file is encountered.
io.read_token(+Port,-RetRort,-Str)
Read a token Str separated by a space or a tab or a newline from the input port Port and returns the token and a new port RetRort. Returns a unary atom 'eof' if the end of file is encountered.
io.read_line(+Port,-RetRort,-Str)
Read a single line Str from the input port Port and returns a new port RetRort.
io.close_port(+Port,-RetRort)
Close Port and returns it as RetRort. Further operations on the port will cause an error.
io.free_port(+Port)
Frees Port.
io.print_byte(+Port,+N,-RetRort)
Print the character with the code N to Port and return a new port RetRort.
io.print_unary(+Port,+C,-RetRort)
Print the name of a unary atom C to Port and return a new port RetRort.
io.print_char(+Port,+C,-RetRort)
Print the name of an atom C to Port and return a new port RetRort. The atom name need not necessarily be a single character.
io.print(+Port,+Str,-RetRort)
Print a string Str to Port and return a new port RetRort.
io.print_line(+Port,+Str,-RetRort)
Print a string Str and a newline to Port and return a new port RetRort.
io.print_newline(+Port,-RetRort)
Print a newline to Port and return a new port RetRort.
io.print_mem(+Port,+M,-RetRort)
Print the content of the membrane M to Port and return a new port RetRort. The membrane must not have free links other than that linked to this API.
io.open_output_string(-SRetRort)
Creates a new string output port SRetRort.
io.open_input_string(+Str,-SRetRort)
Creates a new string input port SRetRort consisting of the characters in the string Str.
io.output_string(+Port,-RetRort,-Str)
Dumps the current content of the string port Port to Str and returns the port as RetRort (without flushing it).

Library nlmem

The library nlmem (nonlinear membrane) is used when coping or removing a cell with free links (i.e., links connected to atoms outside the membrane). When copying such cells, the free links should be split by inserting ternary atoms; when removing such cells, the free links should be terminated by a unary atom. The library nlmem contains an implementation of the following rule schemes that use aggregates:

R=nlmem.copy(X,a), {$p[X|*Z]} :-
   R=copied(X1,X2),
   {$p[X1|*Z1]}, {$p[X2|*Z2]},
   a(*Z1,*Z2,*Z).
nlmem.kill(X,b), {$p[X|*Z]} :- b(*Z).

They are rule schemes in the sense that a and b are metasymbols to be replaced by any symbolic names.

nlmem.copy(+{P},+a,-R)
An abbreviated form of (nlmem.copy(R0,a,R), {+R0,P}). Creates two copies of the cell {+R0,P} with all its free links renamed, and connects R and the two fresh copies of R0 using a ternary atom with the name a. Furthermore, for each free link L of the original cell {+R0, P} (except R0 that will disappear together with the '+'), nlmem.copy connects the two fresh copies of L and the original L via the ternary atom a.
nlmem.copy(+{P},-R)
Same as {nlmem.copy({P},copied,R).
nlmem.kill(+{P},+b)
An abbreviated form of (nlmem.kill(R0,b), {+R0,P}). Connects each free link L of the cell {+R0, P} (except R0 that will disappear together with the '+') to the unary atom b.
nlmem.kill(+{P})
Same as nlmem.kill({P},killed).

Library seq

Library seq is to apply sets of rules R1,..., Rn sequentially to a graph G, that is, rules Rn+1 are applied only after rules in Rn becomes non-applicable.

Each set of rules Rk is specified as a cell containing rules, while the initial graph G is specified as a cell containing G. For instance,

r=seq.run({a}, [{a:-b}, {b:-c. a:-never.}, {c:-d. b:-never.}])

is reduced to

r={d}
r=seq.run(+M,+Rs)
M is a cell (called a data cell) and Rs is a list of cells (called rull cells) each containing rules. Applies rules in Rs to the data cell M sequentially from left to right. When reaction terminates for the rules in some rule cell, these rules are removed and the rules in the next rule cell are inserted into the data cell. Stops execution when stop_seq/0 appears in the cell.

Front page List of pages Search Recent changes Backup   Help   RSS of recent changes