*Rst
- A global variable holding a (possibly empty)
prg body, which
will be executed after error processing. This makes it possible to restart an
application despite of a failure. See also Error
Handling, *Err and *Msg.
: (de loopTest ()
(let N 4
(loop
(println (/ 100 (dec 'N))) ) ) )
-> loopTest
: (de *Rst
(prinl "Loop Failed!")
(wait 4000)
(loopTest) ) # restart
-> *Rst
: (loopTest)
33
50
100
!? (/ 100 (dec 'N))
Div/0
Loop Failed!
33
50
100
!? (/ 100 (dec 'N))
Div/0
Loop Failed!
...
*Run
- This global variable can hold a list of
prg expressions which
are used during key, sync and wait. The first element of each expression must
either be a positive number (thus denoting a file descriptor to wait for) or a
negative number (denoting a timeout value in milliseconds (in that case another
number must follow to hold the remaining time)). A select system
call is performed with these values, and the corresponding prg body
is executed when input data are available or when a timeout occurred. See also
task.
: (de *Run (-2000 0 (println '2sec))) # Install 2-sec-timer
-> *Run
: 2sec # Prints "2sec" every 2 seconds
2sec
2sec
# (Enter) Exit
$
(rand ['cnt1 'cnt2] | ['T]) -> cnt | flg
- Returns a pseudo random number in the range cnt1 .. cnt2 (or -2147483648 ..
+2147483647 if no arguments are given). If the argument is
T, a
boolean value flg is returned. See also seed.
: (rand 3 9)
-> 3
: (rand 3 9)
-> 7
(rank 'any 'lst ['flg]) -> lst
- Searches a ranking list.
lst should be sorted. Returns the
element from lst with a maximal CAR less or equal to
any (if flg is NIL), or with a minimal
CAR greater or equal to any (if flg is
non-NIL), or NIL if no match is found. See also Comparing.
: (rank 0 '((1 . a) (100 . b) (1000 . c)))
-> NIL
: (rank 50 '((1 . a) (100 . b) (1000 . c)))
-> (1 . a)
: (rank 100 '((1 . a) (100 . b) (1000 . c)))
-> (100 . b)
: (rank 300 '((1 . a) (100 . b) (1000 . c)))
-> (100 . b)
: (rank 9999 '((1 . a) (100 . b) (1000 . c)))
-> (1000 . c)
: (rank 50 '((1000 . a) (100 . b) (1 . c)) T)
-> (100 . b)
(raw ['flg]) -> flg
- Console mode control function. When called without arguments, it returns the
current console mode (
NIL for "cooked mode"). Otherwise, the
console is set to the new state. See also key.
$ ./p
: (raw)
-> NIL
$ ./p dbg.l
: (raw)
-> T
(rc 'sym 'any1 ['any2]) -> any
- Fetches a value from a ressource file
sym, or stores a value
any2 in that file, using a key any1. All values are
stored in a list in the file, using assoc. During the whole operation, the file is
exclusively locked with ctl.
: (info "a.rc") # File exists?
-> NIL # No
: (rc "a.rc" 'a 1) # Store 1 for 'a'
-> 1
: (rc "a.rc" 'b (2 3 4)) # Store (2 3 4) for 'b'
-> (2 3 4)
: (rc "a.rc" 'c 'b) # Store 'b' for 'c'
-> b
: (info "a.rc") # Check file
-> (28 733124 . 61673)
: (in "a.rc" (echo)) # Display it
((c . b) (b 2 3 4) (a . 1))
-> T
: (rc "a.rc" 'c) # Fetch value for 'c'
-> b
: (rc "a.rc" @) # Fetch value for 'b'
-> (2 3 4)
(rd ['sym]) -> any
(rd 'cnt) -> num | NIL
- Binary read: Reads one item from the current input channel in encoded binary
format. When called with a
cnt argument (second form), that number
of raw bytes (in big endian format if cnt is positive, otherwise
little endian) is read as a single number. Upon end of file, if the
sym argument is given, it is returned, otherwise NIL.
See also pr and wr.
: (out "x" (pr 'abc "EOF" 123 "def"))
-> "def"
: (in "x" (rd))
-> abc
: (in "x"
(make
(use X
(until (== "EOF" (setq X (rd "EOF"))) # '==' detects end of file
(link X) ) ) ) )
-> (abc "EOF" 123 "def") # as opposed to reading a symbol "EOF"
: (in "/dev/urandom" (rd 20))
-> 396737673456823753584720194864200246115286686486
(read ['sym1 ['sym2]]) -> any
- Reads one item from the current input channel.
NIL is returned
upon end of file. When called without arguments, an arbitrary Lisp expression is
read. Otherwise, a token (a number, or an internal or transient symbol) is read.
In that case, sym1 specifies which set of characters to accept for
continuous symbol namess (in addition to the standard alphanumerical
characters), and sym2 an optional comment character. See also
any, str, skip and eof.
: (list (read) (read) (read)) # Read three things from console
123 # a number
abcd # a symbol
(def # and a list
ghi
jkl
)
-> (123 abcd (def ghi jkl))
: (make (while (read "_" "#") (link @)))
abc = def_ghi("xyz"+-123) # Comment
""
-> (abc = def_ghi "(" "xyz" + - 123 ")")
(recur fun) -> any
(recurse ..) -> any
- Implements anonymous recursion, by defining the function
recurse on the fly. During the execution of fun, the
symbol recurse is bound to the function definition
fun. See also let and
lambda.
: (de fibonacci (N)
(when (lt0 N)
(quit "Bad fibonacci" N) )
(recur (N)
(if (< N 2)
1
(+
(recurse (dec N))
(recurse (- N 2)) ) ) ) )
-> fibonacci
: (fibonacci 22)
-> 28657
: (fibonacci -7)
-7 -- Bad fibonacci
(redef sym . fun) -> sym
- Redefines
sym in terms of itself. The current definition is
saved in a new symbol, which is substituted for each occurrence of
sym in fun, and which is also returned. See also
de, daemon and patch.
: (de hello () (prinl "Hello world!"))
-> hello
: (pp 'hello)
(de hello NIL
(prinl "Hello world!") )
-> hello
: (redef hello (A B)
(println 'Before A)
(prog1 (hello) (println 'After B)) )
-> "hello"
: (pp 'hello)
(de hello (A B)
(println 'Before A)
(prog1 ("hello") (println 'After B)) )
-> hello
: (hello 1 2)
Before 1
Hello world!
After 2
-> "Hello world!"
: (redef * @
(msg (rest))
(pass *) )
-> "*"
: (* 1 2 3)
(1 2 3)
-> 6
(rel var lst [any ..]) -> any
- Defines a relation for
var in the current class *Class, using lst as the list of
classes for that relation, and possibly additional arguments any
for its initialization. See also Database, class, extend, dm and var.
(class +Person +Entity)
(rel nm (+List +Ref +String)) # Names
(rel tel (+Ref +String)) # Telephone
(rel adr (+Joint) prs (+Address)) # Address
(class +Address +Entity)
(rel Cit (+Need +Hook +Link) (+City)) # City
(rel str (+List +Ref +String) Cit) # Street
(rel prs (+List +Joint) adr (+Person)) # Inhabitants
(class +City +Entity)
(rel nm (+List +Ref +String)) # Zip / Names
(remove 'cnt 'lst) -> lst
- Removes the element at position
cnt from lst. See
also insert, place, append, delete and replace.
: (remove 3 '(a b c d e))
-> (a b d e)
: (remove 1 '(a b c d e))
-> (b c d e)
: (remove 9 '(a b c d e))
-> (a b c d e)
(replace 'lst 'any1 'any2 ..) -> lst
- Replaces in
lst all occurrences of any1 with
any2. For optional additional argument pairs, this process is
repeated. See also append, delete, insert, remove and place.
: (replace '(a b b a) 'a 'A)
-> (A b b A)
: (replace '(a b b a) 'b 'B)
-> (a B B a)
: (replace '(a b b a) 'a 'B 'b 'A)
-> (B A A B)
(request 'typ 'var ['hook] 'val ..) -> obj
- Returns a database object. If a matching object cannot be found (using
db), a new object of the given type is
created (using new). See also obj.
: (request '(+Item) 'nr 2)
-> {3-2}
(rest) -> lst
- Can only be used inside functions with a variable number of arguments (with
@). Returns the list of all remaining arguments from the internal
list. See also args, next, arg and pass.
: (de foo @ (println (rest)))
-> foo
: (foo 1 2 3)
(1 2 3)
-> (1 2 3)
(reverse 'lst) -> lst
- Returns a reversed copy of
lst. See also flip.
: (reverse (1 2 3 4))
-> (4 3 2 1)
(rewind) -> flg
- Sets the file position indicator for the current output stream to the
beginning of the file, and truncates the file length to zero. Returns
T when successful. See also flush.
: (out "a" (prinl "Hello world"))
-> "Hello world"
: (in "a" (echo))
Hello world
-> T
: (info "a")
-> (12 733216 . 53888)
: (out "a" (rewind))
-> T
: (info "a")
-> (0 733216 . 53922)
(rollback) -> flg
- Cancels a transaction, by discarding all modifications of external symbols.
For nested transactions, only the changes since the last call to
begin are discarded. Returns T
when the topmost transaction is cancelled. See also commit.
: (pool "db")
-> T
: (begin)
-> T
: (rollback) # Rollback second level
-> NIL
: (rollback) # Rollback top level
-> T
(root 'tree) -> (num . sym)
- Returns the root of a database index tree, with the number of entries in
num, and the base node in sym. See also tree.
: (root (tree 'nr '+Item))
-> (7 . {7-1})
(rot 'lst ['cnt]) -> lst
- Rotate: The contents of the cells of
lst are (destructively)
shifted right, and the value from the last cell is stored in the first cell.
Without the optional cnt argument, the whole list is rotated.
Otherwise only the first cnt elements are rotated.
: (rot (1 2 3 4)) # Rotate all four elements
-> (4 1 2 3)
: (rot (1 2 3 4 5 6) 3) # Rotate only the first three elements
-> (3 1 2 4 5 6)
(rpc 'sym ['any ..]) -> flg
- Rapid (or remote) procedure call: Send an executable list
(sym any ..) via standard output in encoded binary format. See also
pr, pipe, tell and hear.
: (hear (pipe (do 3 (wait 2000) (rpc 'println ''Ok))))
-> 3
: Ok # every two seconds
Ok
Ok
(run 'any ['cnt]) -> any
- If
any is an atom, run behaves like
eval. Otherwise any is a list, which is evaluated in
sequence. The last result is returned. If a binding environment offset
cnt is given, that evaluation takes place in the corresponding
environment. See also eval and
up.
: (run '((println (+ 1 2 3)) (println 'Ok)))
6
Ok
-> Ok