*PPid
NIL if the current process is a top level process.
: (println *PPid *Pid)
NIL 5286
: (unless (fork) (println *PPid *Pid) (bye))
5286 5522
*Pid
: *Pid
-> 6386
: (call "ps") # Show processes
PID TTY TIME CMD
.... ... ........ .....
6386 pts/1 00:00:00 bin/picolisp # <- current process
6388 pts/1 00:00:00 ps
-> T
(pack 'any ..) -> sym
any. A NIL arguments contributes nothing to the result
string, a number is converted to a digit string, a symbol supplies the
characters of its name, and for a list its elements are taken. See also text and glue.
: (pack 'car " is " 1 '(" symbol " name))
-> "car is 1 symbol name"
(pad 'cnt 'num) -> sym
num packed with leading '0' characters, up to a
field width of cnt. See also format and align.
: (pad 5 1)
-> "00001"
: (pad 5 123456789)
-> "123456789"
(pair 'any) -> any
any when the argument a cons pair cell. See also
atom.
: (pair NIL)
-> NIL
: (pair (1 . 2))
-> (1 . 2)
: (pair (1 2 3))
-> (1 2 3)
part/3
folding it to a
canonical form, is a substring of the folded string representation of the
result of applying the get algorithm to
the following arguments. Typically used as filter predicate in select/3 database queries. See also
sub?, isa/2, same/3, bool/3, range/3, head/3, fold/3 and tolr/3.
: (?
@Nr (1 . 5)
@Nm "part"
(select (@Item)
((nr +Item @Nr) (nm +Item @Nm))
(range @Nr @Item nr)
(part @Nm @Item nm) ) )
@Nr=(1 . 5) @Nm="part" @Item={3-1} @Nr=(1 . 5) @Nm="part" @Item={3-2}
-> NIL
(pass 'fun ['any ..]) -> any
fun all arguments any, and all remaining
variable arguments (@) as they would be returned by rest. (pass 'fun 'any) is
equivalent to (apply 'fun (rest) 'any). See also apply.
: (de bar (A B . @)
(println 'bar A B (rest)) )
-> bar
: (de foo (A B . @)
(println 'foo A B)
(pass bar 1)
(pass bar 2) )
-> foo
: (foo 'a 'b 'c 'd 'e 'f)
foo a b
bar 1 c (d e f)
bar 2 c (d e f)
-> (d e f)
(pat? 'any) -> pat | NIL
any when the argument any is a symbol
whose name starts with an at-mark "@", otherwise NIL.
: (pat? '@)
-> @
: (pat? "@Abc")
-> "@Abc"
: (pat? "ABC")
-> NIL
: (pat? 123)
-> NIL
(patch 'lst 'any . prg) -> any
lst, that
match the pattern any,
by the result of the execution of prg. See also daemon and redef.
: (pp 'hello)
(de hello NIL
(prinl "Hello world!") )
-> hello
: (patch hello 'prinl 'println)
-> NIL
: (pp 'hello)
(de hello NIL
(println "Hello world!") )
-> hello
: (patch hello '(prinl @S) (fill '(println "We said: " . @S)))
-> NIL
: (hello)
We said: Hello world!
-> "Hello world!"
(path 'any) -> sym
@" character in the any
argument with the PicoLisp Home Directory, as it was remembered during
interpreter startup. Optionally, the name may be preceded by a "+"
character (as used by out). This
mechanism is used internally by all I/O functions. See also Invocation, basename. and dirname.
$ /usr/bin/picolisp /usr/lib/picolisp/lib.l
: (path "a/b/c")
-> "a/b/c"
: (path "@a/b/c")
-> "/usr/lib/picolisp/a/b/c"
: (path "+@a/b/c")
-> "+/usr/lib/picolisp/a/b/c"
(peek) -> sym
char would return. See also skip.
$ cat a
# Comment
abcd
$ ./dbg
: (in "a" (list (peek) (char)))
-> ("#" "#")
permute/2
append/3.
: (? (permute (a b c) @X))
@X=(a b c)
@X=(a c b)
@X=(b a c)
@X=(b c a)
@X=(c a b)
@X=(c b a)
-> NIL
(pick 'fun 'lst ..) -> any
fun to successive elements of lst until
non-NIL is returned. Returns that value, 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. (pick 'fun 'lst) is
equivalent to (fun (find 'fun 'lst)). See also seek, find and extract.
: (setq A NIL B 1 C NIL D 2 E NIL F 3)
-> 3
: (find val '(A B C D E))
-> B
: (pick val '(A B C D E))
-> 1
(pid 'pid|lst . exe) -> any
exe when the value of the global *Pid is equal to the pid argument,
or a member of the lst argument. Used typically in combination with
tell to send a command selectively to
another process.
: (tell 'pid 20290 'gc 0) # Tell process 20290 to purge unused heap blocks
-> 0
Note: This function is deprecated, and will be removed in
the next version. Please use the PID argument feature of tell
instead. With that, the above example reduces to
: (tell 20290 'gc 0)
-> 0
(pilog 'lst . prg) -> any
prg for each result set with all Pilog variables bound to their
matching values. See also solve,
?, goal and prove.
: (pilog '((append @X @Y (a b c))) (println @X '- @Y))
NIL - (a b c)
(a) - (b c)
(a b) - (c)
(a b c) - NIL
-> NIL
(pipe exe) -> cnt
(pipe exe . prg) -> any
exe in a fork'ed child process (which terminates
thereafter). In the first form, pipe just returns a file descriptor
to read from the standard output of that process. In the second form, it opens
the standard output of that process as input channel during the execution of
prg. The current input channel will be saved and restored
appropriately. See also ipid, in, out
and rpc.
: (pipe # equivalent to 'any'
(prinl "(a b # Comment^Jc d)") # (child process)
(read) ) # (parent process)
-> (a b c d)
: (pipe # pipe through an external program
(out '(tr "[a-z]" "[A-Z]") # (child process)
(prinl "abc def ghi") )
(line T) ) # (parent process)
-> "ABC DEF GHI"
(place 'cnt 'lst 'any) -> lst
any into lst at position cnt.
See also insert, remove, append, delete and replace.
: (place 3 '(a b c d e) 777)
-> (a b 777 d e)
: (place 1 '(a b c d e) 777)
-> (777 b c d e)
: (place 9 '(a b c d e) 777)
-> (a b c d e 777)
(poll 'cnt) -> cnt | NIL
cnt. See also open,
in and close.
: (and (poll *Fd) (in @ (read))) # Prevent blocking
(pool ['sym1 ['lst] ['sym2] ['sym3]]) -> T
sym1 as a database file in read/write mode. If
the file does not exist, it is created. A currently open database is closed.
lst is a list of block size scale factors (i.e. numbers),
defaulting to (2) (for a single file with a 256 byte block size). If
lst is given, an individual database file is opened for each item.
If sym2 is non-NIL, it is opened in append-mode as an
asynchronous replication journal. If sym3 is non-NIL,
it is opened for reading and appending, to be used as a synchronous transaction
log during commits. See also
dbs, *Dbs and journal.
: (pool "/dev/hda2")
-> T
: *Dbs
-> (1 2 2 4)
: (pool "dbFile" *Dbs)
-> T
:
abu:~/pico ls -l dbFile*
-rw-r--r-- 1 abu abu 256 2007-06-11 07:57 dbFile1
-rw-r--r-- 1 abu abu 13 2007-06-11 07:57 dbFile2
-rw-r--r-- 1 abu abu 13 2007-06-11 07:57 dbFile3
-rw-r--r-- 1 abu abu 13 2007-06-11 07:57 dbFile4
(pop 'var) -> any
var. See also
push, queue, cut, del and fifo.
: (setq S '((a b c) (1 2 3)))
-> ((a b c) (1 2 3))
: (pop S)
-> a
: (pop (cdr S))
-> 1
: (pop 'S)
-> (b c)
: S
-> ((2 3))
(port ['T] 'cnt|(cnt . cnt) ['var]) -> cnt
cnt (or a UDP-Port if the first argument is
T), and returns a socket descriptor suitable as an argument for
listen or accept (or udp, respectively). If cnt is zero,
some free port number is allocated. If a pair of cnts is given
instead, it should be a range of numbers which are tried in turn. When
var is given, it is bound to the port number.
: (port 0 'A) # Allocate free port
-> 4
: A
-> 1034 # Got 1034
: (port (4000 . 4008) 'A) # Try one of these ports
-> 5
: A
-> 4002
(pp 'sym) -> sym
(pp 'sym 'cls) -> sym
(pp '(sym . cls)) -> sym
sym. The
output format would regenerate that same definition when read and executed. See
also pretty, debug and vi.
: (pp 'tab)
(de tab (Lst . @)
(for N Lst
(let V (next)
(and (gt0 N) (space (- N (length V))))
(prin V)
(and
(lt0 N)
(space (- 0 N (length V))) ) ) )
(prinl) )
-> tab
: (pp 'has> '+Entity)
(dm has> (Var Val)
(or
(nor Val (get This Var))
(has> (meta This Var) Val (get This Var)) ) )
-> has>
: (more (can 'has>) pp)
(dm (has> . +relation) (Val X)
(and (= Val X) X) )
(dm (has> . +Fold) (Val X)
(extra
Val
(if (= Val (fold Val)) (fold X) X) ) )
(dm (has> . +Entity) (Var Val)
(or
(nor Val (get This Var))
(has> (meta This Var) Val (get This Var)) ) )
(dm (has> . +List) (Val X)
(and
Val
(or
(extra Val X)
(find '((X) (extra Val X)) X) ) ) )
(dm (has> . +Bag) (Val X)
(and
Val
(or (super Val X) (car (member Val X))) ) )
(pr 'any ..) -> any
any arguments to the current output
channel in encoded binary format. See also rd, tell, hear, rpc and wr.
: (out "x" (pr 7 "abc" (1 2 3) 'a)) # Print to "x"
-> a
: (hd "x")
00000000 04 0E 0E 61 62 63 01 04 02 04 04 04 06 03 05 61 ...abc.........a
-> NIL
(prEval 'prg ['cnt]) -> any
prg, similar to run, by evaluating all expressions in
prg (within the binding environment given by cnt-1).
As a side effect, all atomic expressions will be printed with prinl. See also eval.
: (let Prg 567
(prEval
'("abc" (prinl (+ 1 2 3)) Prg 987) ) )
abc
6
567
987
-> 987
(pre? 'any1 'any2) -> any2 | NIL
any2 when the string representation of
any1 is a prefix of the string representation of any2.
See also sub?.
: (pre? "abc" "abcdef")
-> "abcdef"
: (pre? "def" "abcdef")
-> NIL
: (pre? (+ 3 4) "7fach")
-> "7fach"
: (pre? NIL "abcdef")
-> "abcdef"
(pretty 'any 'cnt)
any. If any is an atom, or a list
with a size not greater than 12, it is
printed as is. Otherwise, only the
opening parenthesis and the CAR of the list is printed, all other elementes are
pretty-printed recursively indented by three spaces, followed by a space and the
corresponding closing parenthesis. The initial indentation level
cnt defaults to zero. See also pp.
: (pretty '(a (b c d) (e (f (g) (h) (i)) (j (k) (l) (m))) (n o p) q))
(a
(b c d)
(e
(f (g) (h) (i))
(j (k) (l) (m)) )
(n o p)
q )-> ")"
(prin 'any ..) -> any
any arguments to the
current output channel. No space or newline is printed between individual items,
or after the last item. For lists, all elements are prin'ted
recursively. See also prinl.
: (prin 'abc 123 '(a 1 b 2))
abc123a1b2-> (a 1 b 2)
(prinl 'any ..) -> any
any arguments to the
current output channel, followed by a newline. No space or newline is printed
between individual items. For lists, all elements are prin'ted
recursively. See also prin.
: (prinl 'abc 123 '(a 1 b 2))
abc123a1b2
-> (a 1 b 2)
(print 'any ..) -> any
any arguments to the current output channel. If
there is more than one argument, a space is printed between successive
arguments. No space or newline is printed after the last item. See also println, printsp, sym and str
: (print 123)
123-> 123
: (print 1 2 3)
1 2 3-> 3
: (print '(a b c) 'def)
(a b c) def-> def
(println 'any ..) -> any
any arguments to the current output channel,
followed by a newline. If there is more than one argument, a space is printed
between successive arguments. See also print, printsp.
: (println '(a b c) 'def)
(a b c) def
-> def
(printsp 'any ..) -> any
any arguments to the current output channel,
followed by a space. If there is more than one argument, a space is printed
between successive arguments. See also print, println.
: (printsp '(a b c) 'def)
(a b c) def -> def
(proc 'sym ..) -> T
sym
arguments, using the system ps utility. See also hd.
: (proc 'picolisp)
PID PPID STARTED SZ %CPU WCHAN CMD
9781 8895 16:06:53 2536 0.8 select ./bin/picolisp -on *Dbg ./lib.l @ext.l @dbg.l app/main.l lib/too.l -main -go
9884 9781 16:07:01 2540 0.0 wait ./bin/picolisp -on *Dbg ./lib.l @ext.l @dbg.l app/main.l lib/too.l -main -go
-> T
(prog . prg) -> any
prg, and returns the result of the last expression.
See also nil, t, prog1 and prog2.
: (prog (print 1) (print 2) (print 3))
123-> 3
(prog1 'any1 . prg) -> any1
any1. See also nil,
t, prog and prog2.
: (prog1 (print 1) (print 2) (print 3))
123-> 1
(prog2 'any1 'any2 . prg) -> any2
any2. See also nil,
t, prog and prog1.
: (prog2 (print 1) (print 2) (print 3))
123-> 2
(prop 'sym1|lst ['sym2|cnt ..] 'sym) -> lst|sym
sym from a symbol. That
symbol is sym1 (if no other arguments are given), or a symbol found
by applying the get algorithm to
sym1|lst and the following arguments. The property (the cell, not
just its value) is returned, suitable for direct (destructive) manipulations.
See also ::.
: (put 'X 'cnt 0)
-> 0
: (prop 'X 'cnt)
-> (0 . cnt)
: (inc (prop 'X 'cnt)) # Directly manipulate the property value
-> 1
: (get 'X 'cnt)
-> 1
(protect . prg) -> any
prg, and returns the result of the last expression. If
a signal is received during that time, its handling will be delayed until the
execution of prg is completed. See also alarm, *Hup, *Sig[12] and kill.
: (protect (journal "db1.log" "db2.log"))
-> T
(prove 'lst ['lst]) -> lst
NIL if not successful. The query list is modified as a
side effect, allowing subsequent calls to prove for further
results. The optional second argument may contain a list of symbols; in that
case the successful matches of rules defined for these symbols will be traced.
See also goal, -> and unify.
: (prove (goal '((equal 3 3))))
-> T
: (prove (goal '((equal 3 @X))))
-> ((@X . 3))
: (prove (goal '((equal 3 4))))
-> NIL
(prune ['flg])
flg is
non-NIL, further pruning will be disabled. See also lieu.
(in File1
(while (someData)
(new T '(+Cls1) ..)
(at (0 . 10000) (commit) (prune)) ) )
(in File2
(while (moreData)
(new T '(+Cls2) ..)
(at (0 . 10000) (commit) (prune)) ) )
(commit)
(prune T)
(push 'var 'any ..) -> any
var. The any
arguments are cons'ed in front of the value list. See also push1, pop, queue and fifo.
: (push 'S 3) # Use the VAL of 'S' as a stack
-> 3
: S
-> (3)
: (push 'S 2)
-> 2
: (push 'S 1)
-> 1
: S
-> (1 2 3)
: (push S 999) # Now use the CAR of the list in 'S'
-> 999
: (push S 888 777)
-> 777
: S
-> ((777 888 999 . 1) 2 3)
(push1 'var 'any ..) -> any
var. Each any argument
is cons'ed in front of the value list only if it is not already a member of that list. See also push, pop and queue.
: (push1 'S 1 2 3)
-> 3
: S
-> (3 2 1)
: (push1 'S 2 4)
-> 4
: S
-> (4 3 2 1)
(put 'sym1|lst ['sym2|cnt ..] 'sym|0 'any) -> any
any for a property key sym (or
in the value cell for zero) in a symbol. That symbol is sym1 (if no
other arguments are given), or a symbol found by applying the get algorithm to sym1|lst and the
following arguments. See also =:.
: (put 'X 'a 1)
-> 1
: (get 'X 'a)
-> 1
: (prop 'X 'a)
-> (1 . a)
: (setq L '(A B C))
-> (A B C)
: (setq B 'D)
-> D
: (put L 2 0 'p 5) # Store '5' under the 'p' propery of the value of 'B'
-> 5
: (getl 'D)
-> ((5 . p))
(put! 'obj 'sym 'any) -> any
put. Note that for setting property values of
entities typically the put!> message is used. See also
new!, set! and inc!.
(put! Obj 'cnt 0) # Setting a property of a non-entity object
(putl 'sym1|lst1 ['sym2|cnt ..] 'lst) -> lst
lst in a symbol. That
symbol is sym1 (if no other arguments are given), or a symbol found
by applying the get algorithm to
sym1|lst1 and the following arguments. All previously defined
properties for that symbol are lost. See also getl and maps.
: (putl 'X '((123 . a) flg ("Hello" . b)))
-> ((123 . a) flg ("Hello" . b))
: (get 'X 'a)
-> 123
: (get 'X 'b)
-> "Hello"
: (get 'X 'flg)
-> T
(pwd) -> sym
dir and cd.
: (pwd)
-> "/home/app/"