*Fork
- A global variable holding a (possibly empty)
prg body, to be
executed after a call to fork in the
child process.
: (push '*Fork '(off *Tmp)) # Clear '*Tmp' in child process
-> (off *Tmp)
(fetch 'tree 'any) -> any
- Fetches a value for the key
any from a database tree. See also
tree and store.
: (fetch (tree 'nr '+Item) 2)
-> {3-2}
(fifo 'var ['any]) -> any
- Implements a first-in-first-out structure using a circular list. When called
with an
any argument, it will be concatenated to end of the
structure. Otherwise, the first element is removed from the structure and
returned. See also queue, push, pop, rot and circ.
: (fifo 'X 1)
-> 1
: (fifo 'X 2)
-> 2
: (fifo 'X 3)
-> 3
: X
-> (3 1 2 .)
: (fifo 'X)
-> 1
: (fifo 'X)
-> 2
: X
-> (3 .)
(fill 'any ['sym|lst]) -> any
- Fills a pattern
any, by substituting sym, or all
symbols in lst, or - if no second argument is given - each pattern
symbol in any (see pat?),
with its current value. In that case, @ itself is not considered a
pattern symbol. See also match.
: (setq @X 1234 @Y (1 2 3 4))
-> (1 2 3 4)
: (fill '@X)
-> 1234
: (fill '(a b (c @X) ((@Y . d) e)))
-> (a b (c 1234) (((1 2 3 4) . d) e))
: (let X 2 (fill (1 X 3) 'X))
-> (1 2 3)
(filter 'fun 'lst ..) -> lst
- Applies
fun to each element of lst. When
additional lst arguments are given, their elements are also passed
to fun. Returns a list of all elements of lst where
fun returned non-NIL. See also fish.
: (filter num? (1 A 2 (B) 3 CDE))
-> (1 2 3)
(fin 'any) -> num|sym
- Returns
any if it is an atom, otherwise the CDR of
its last cell. See also last and
tail.
: (fin 'a)
-> a
: (fin '(a . b))
-> b
: (fin '(a b . c))
-> c
: (fin '(a b c))
-> NIL
(finally exe . prg) -> any
prg is executed, then exe is evaluated, and the
result of prg is returned. exe will also be evaluated
if prg does not terminate normally due to a runtime error or a call
to throw. See also bye, catch, quit and Error
Handling.
: (finally (prinl "Done!")
(println 123)
(quit)
(println 456) )
123
Done!
: (catch 'A
(finally (prinl "Done!")
(println 1)
(throw 'A 123)
(println 2) ) )
1
Done!
-> 123
(find 'fun 'lst ..) -> any
- Applies
fun to successive elements of lst until
non-NIL is returned. Returns that element, or NIL if
fun did not return non-NIL for any element of
lst. When additional lst arguments are given, their
elements are also passed to fun. See also seek, pick.
: (find pair (1 A 2 (B) 3 CDE))
-> (B)
: (find '((A B) (> A B)) (1 2 3 4 5 6) (6 5 4 3 2 1))
-> 4
: (find > (1 2 3 4 5 6) (6 5 4 3 2 1)) # shorter
-> 4
(fish 'fun 'any) -> lst
- Applies
fun to each element - and recursively to all sublists -
of lst. Returns a list of all items where fun returned
non-NIL. See also filter.
: (fish gt0 '(a -2 (1 b (-3 c 2)) 3 d -1))
-> (1 2 3)
: (fish sym? '(a -2 (1 b (-3 c 2)) 3 d -1))
-> (a b c d)
(flg? 'any) -> flg
- Returns
T when the argument any is either
NIL or T. See also bool. (flg? X) is equivalent to
(or (not X) (=T X)).
: (flg? (= 3 3))
-> T
: (flg? (= 3 4))
-> T
: (flg? (+ 3 4))
-> NIL
(flip 'lst) -> lst
- Returns
lst (destructively) reversed. See also reverse.
: (flip (1 2 3 4))
-> (4 3 2 1)
(flush) -> flg
- Flushes the current output stream by writing all buffered data. A call to
flush for standard output is done automatically before a call to
key. Returns T when
successful. See also rewind.
: (flush)
-> T
(fmt64 'num) ->sym
(fmt64 'sym) -> num
- Converts a number
num to a string in base-64, or a base-64
formatted string to a number. The digits are represented with the characters
0-9, :, ;,
A-Z and a-z. This format is
used internally for the names of external
symbols. See also hex and
oct.
: (fmt64 9)
-> "9"
: (fmt64 10)
-> ":"
: (fmt64 11)
-> ";"
: (fmt64 12)
-> "A"
: (fmt64 "100")
-> 4096
(fold 'any ['cnt]) -> sym
- Folding to a canonical form: If
any is not a symbol,
NIL is returned. Otherwise, a new transient symbol with all digits
and all letters of any, converted to lower case, is returned. If
the cnt argument is given, the result is truncated to that length
(or not truncated if cnt is zero). Otherwise cnt
defaults to 24. See also lowc.
: (fold " 1A 2-b/3")
-> "1a2b3"
: (fold " 1A 2-B/3" 3)
-> "1a2"
(for sym|(sym2 . sym) 'lst ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any
(for (sym|(sym2 . sym) 'any1 'any2 [. prg]) ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any
- Conditional loop with local variable(s) and multiple conditional exits: In
the first form, the value of
sym is saved, sym is
subsequently bound to the elements of lst, and the body is executed
each time. In the second form, the value of sym is saved, and
sym is bound to any1. If sym2 is given,
it is treated as a counter variable, first bound to 1 and then incremented for
each execution of the body. While the condition any2 evaluates to
non-NIL, the body is repeatedly executed and, if prg
is given, sym is re-bound to the result of its evaluation. If a
clause has NIL or T as its CAR, the
clause's second element is evaluated as a condition and - if the result is
NIL or non-NIL, respectively - the prg is
executed and the result returned. If the body is never executed,
NIL is returned. See also do and loop.
: (for (N 1 (>= 8 N) (inc N)) (printsp N))
1 2 3 4 5 6 7 8 -> 8
: (for (L (1 2 3 4 5 6 7 8) L) (printsp (pop 'L)))
1 2 3 4 5 6 7 8 -> 8
: (for X (1 a 2 b) (printsp X))
1 a 2 b -> b
: (for ((I . L) '(a b c d e f) L (cddr L)) (println I L))
1 (a b c d e f)
2 (c d e f)
3 (e f)
-> (e f)
: (for (I . X) '(a b c d e f) (println I X))
1 a
2 b
3 c
4 d
5 e
6 f
-> f
(fork) -> pid | NIL
- Forks a child process. Returns
NIL in the child, and the
child's process ID pid in the parent. In the child, the
VAL of the global variable *Fork (should be a prg) is
executed. See also pipe and tell.
: (unless (fork) (do 5 (println 'Ok) (wait 1000)) (bye))
-> NIL
Ok # Child's output
: Ok
Ok
Ok
Ok
(format 'num ['cnt ['sym1 ['sym2]]]) -> sym
(format 'sym ['cnt ['sym1 ['sym2]]]) -> num
- Converts a number
num to a string, or a string sym
to a number. In both cases, optionally a precision cnt, a
decimal-separator sym1 and a thousands-separator sym2
can be supplied. Returns NIL if the conversion is unsuccessful. See
also Numbers.
: (format 123456789) # Integer conversion
-> "123456789"
: (format 123456789 2) # Fixed point
-> "1234567.89"
: (format 123456789 2 ",") # Comma as decimal-separator
-> "1234567,89"
: (format 123456789 2 "," ".") # and period as thousands-separator
-> "1.234.567,89"
:
: (format "123456789") # String to number
-> 123456789
: (format "1234567.89" 4) # scaled to four digits
-> 12345678900
: (format "1.234.567,89") # separators not recognized
-> NIL
: (format "1234567,89" 4 ",")
-> 12345678900
: (format "1.234.567,89" 4 ",") # thousands-separator not recognized
-> NIL
: (format "1.234.567,89" 4 "," ".")
-> 12345678900
(free 'cnt) -> (sym . lst)
- Returns, for the
cnt'th database file, the next available
symbol sym (i.e. the first symbol greater than any symbol in the
database), and the list lst of free symbols. See also seq, zap and dbck.
: (pool "x") # A new database
-> T
: (new T) # Create a new symbol
-> {2}
: (new T) # Create another symbol
-> {3}
: (commit) # Commit changes
-> T
: (zap '{2}) # Delete the first symbol
-> {2}
: (free 1) # Show free list
-> ({4}) # {3} was the last symbol allocated
: (commit) # Commit the deletion of {2}
-> T
: (free 1) # Now {2} is in the free list
-> ({4} {2})
(from 'any ..) -> sym
- Skips the current input channel until one of the strings
any is
found, and starts subsequent reading from that point. The found any
argument, or NIL (if none is found) is returned. See also till and echo.
: (and (from "val='") (till "'" T))
test val='abc'
-> "abc"
(fun? 'any) -> any
- Returns
NIL when the argument any is neither a
number suitable for a code-pointer, nor a list suitable for a lambda expression
(function). Otherwise a number is returned for a code-pointer, T
for a function without arguments, and a single formal parameter or a list of
formal parameters for a function. See also getd.
: (fun? 1000000000) # Might be a code pointer
-> 1000000000
: (fun? 100000000000000) # Too big for a code pointer
-> NIL
: (fun? 1000000001) # Cannot be a code pointer (odd)
-> NIL
: (fun? '((A B) (* A B))) # Lambda expression
-> (A B)
: (fun? '((A B) (* A B) . C)) # Not a lambda expression
-> NIL
: (fun? '(1 2 3 4)) # Not a lambda expression
-> NIL
: (fun? '((A 2 B) (* A B))) # Not a lambda expression
-> NIL