- *Blob
- A global variable holding the pathname of the database blob directory. See
also blob.
: *Blob
-> "blob/app/"
 
- *Bye
- A global variable holding a (possibly empty) prgbody, to be
executed just before the termination of the PicoLisp interpreter. See alsobyeandtmp.
: (push1 '*Bye '(call 'rm "myfile.tmp"))  # Remove a temporary file
-> (call 'rm "myfile.tmp")
 
- +Bag
- Class for a list of arbitrary relations, a subclass of +relation. Objects of that class maintain
a list of heterogeneous relations. Typically used in combination with the+Listprefix class, to maintain small
two-dimensional tables within objects. See also Database.
(rel pos (+List +Bag)         # Positions
   ((+Ref +Link) NIL (+Item))    # Item
   ((+Number) 2)                 # Price
   ((+Number))                   # Quantity
   ((+String))                   # Memo text
   ((+Number) 2) )               # Total amount
 
- +Blob
- Class for blob relations, a subclass of +relation. Objects of that class maintain
blobs, as stubs in database objects pointing to actual files for arbitrary
(often binary) data. The files themselves reside below the path specified by the*Blobvariable. See also Database.
(rel jpg (+Blob))  # Picture
 
- +Bool
- Class for boolean relations, a subclass of +relation. Objects of that class expect
eitherTorNILas value (though, as always, only
non-NILwill be physically stored in objects). See also Database.
(rel ok (+Ref +Bool))  # Indexed flag
 
- (balance 'var 'lst ['flg])
- Builds a balanced binary idxtree
invar, from the sorted list inlst. Normally, if
arbitary - or, in the worst case, ordered - data are inserted withidx, the tree will not be balanced. But iflstis
properly sorted, its contents will be inserted in an optimally balanced way. Ifflgis non-NIL, the index tree will be augmented
instead of being overwritten. See alsoComparingandsort.
# Normal idx insert
: (off I)
-> NIL
: (for X (1 4 2 5 3 6 7 9 8) (idx 'I X T))
-> NIL
: (depth I)
-> (7 . 4)
# Balanced insert
: (balance 'I (sort (1 4 2 5 3 6 7 9 8)))
-> NIL
: (depth I)
-> 4
# Augment
: (balance 'I (sort (10 40 20 50 30 60 70 90 80)) T)
-> NIL
: (idx 'I)
-> (1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90)
 
- (basename 'any) -> sym
- Returns the filename part of a path name any. See alsodirnameandpath.
: (basename "a/b/c/d")
-> "d"
 
- (be sym . any) -> sym
- Declares a Pilog fact or rule for the
symargument, by concatenating theanyargument to theTproperty ofsym. Groups of declarations are
collected for a givensym. Whensymchanges, i.e. when
it differs from the one in the previous declaration, the current group is
considered to be complete and a new group is started. Laterbedeclarations for a previously completed symbol will reset its rules, to allow
repeated reloading of source files.
See alsoclause,asserta,assertz,retract,rules,goalandprove.
: (be likes (John Mary))
-> likes
: (be likes (John @X) (likes @X wine) (likes @X food))
-> likes
: (get 'likes T)
-> (((John Mary)) ((John @X) (likes @X wine) (likes @X food)))
: (rules 'likes)
1 (be likes (John Mary))
2 (be likes (John @X) (likes @X wine) (likes @X food))
-> likes
: (? (likes John @X))
 @X=Mary
-> NIL
 
- (beep) -> any
- Send the bell character to the console. See also space,prinandchar.
: (beep)
-> "^G"
 
- (bench . prg) -> any
- (Debug mode only) Benchmarks prg, by printing the time it took
to execute, and returns the result. See alsousec.
: (bench (wait 2000))
1.996 sec
-> NIL
 
- (bin 'num ['num]) -> sym
- (bin 'sym) -> num
- Converts a number numto a binary string, or a binary stringsymto a number. In the first case, if the second argument is
given, the result is separated by spaces into groups of such many digits. See
alsooct,hex,haxandformat.
: (bin 73)
-> "1001001"
: (bin "1001001")
-> 73
: (bin 1234567 4)
-> "1 0010 1101 0110 1000 0111"
 
- (bind 'sym|lst . prg) -> any
- Binds value(s) to symbol(s). The first argument must evaluate to a symbol,
or a list of symbols or symbol-value pairs. The values of these symbols are
saved (and the symbols bound to the values in the case of pairs),
prgis executed, then the symbols are restored to their original
values. During execution ofprg, the values of the symbols can be
temporarily modified. The return value is the result ofprg. See
alsolet,jobanduse.
: (setq X 123)                               # X is 123
-> 123
: (bind 'X (setq X "Hello") (println X))  # Set X to "Hello", print it
"Hello"
-> "Hello"
: (bind '((X . 3) (Y . 4)) (println X Y) (* X Y))
3 4
-> 12
: X
-> 123                                       # X is restored to 123
 
- (bit? 'num ..) -> num | NIL
- Returns the first numargument when all bits which are 1 in the
first argument are also 1 in all following arguments, otherwiseNIL. When one of those arguments evaluates toNIL, it
is returned immediately. See also&,|andx|.
: (bit? 7 15 255)
-> 7
: (bit? 1 3)
-> 1
: (bit? 1 2)
-> NIL
 
- (blk 'fd 'cnt 'siz ['fd2]) -> lst
- (blk 'fd 0) -> (cnt . siz)
- Reads raw object data from the cnt'th block in the file open on
descriptorfd. Returns a cons pair of the value and property list
of that database object, orNILfor an invalid block. Ifcntis zero, a cons pair of the total number of blocks in the file
and the file's block size scale factor is returned. Otherwise,sizshould be the block size scale factor. Iffd2is given, a read
(shared) lock is set on that file during the read operation. See alsopool,pool2,id,ctlandqsym.
: (show '{4})
{4} (+Role)
   usr ({15} {13} {11})
   perm (Customer Item Order Report Delete)
   nm "Accounting"
-> {4}
: (open "db/app/@")
-> 15
: (blk 15 4 3 15)
-> ((+Role) (({15} {13} {11}) . usr) ((Customer Item Order Report Delete) . perm) ("Accounting" . nm))
 
- (blob 'obj 'sym) -> sym
- Returns the blob file name for varinobj. See
also*Blob,blob!andpack.
: (show (db 'nr '+Item 1))
{B1} (+Item)
   jpg
   pr 29900
   inv 100
   sup {C1}
   nm "Main Part"
   nr 1
-> {B1}
: (blob '{B1} 'jpg)
-> "blob/app/3/-/1.jpg"
 
- (blob! 'obj 'sym 'file)
- Stores the contents of filein ablob. See alsoput!>.
(blob! *ID 'jpg "picture.jpg")
 
- (bool 'any) -> flg
- Returns Twhen the argumentanyis
non-NIL. This function is only needed whenTis
strictly required for a "true" condition (Usually, any non-NILvalue is considered to be "true"). See alsoflg?.
: (and 3 4)
-> 4
: (bool (and 3 4))
-> T
 
- bool/3
- Pilog predicate that succeeds if the first
argument has the same truth value as the result of applying the getalgorithm to the following arguments.
Typically used as filter predicate inselect/3database queries. See alsobool,isa/2,same/3,range/3,head/3,fold/3,part/3andtolr/3.
: (? @OK T           # Find orders where the 'ok' flag is set
   (db nr +Ord @Ord)
   (bool @OK @Ord ok) )
 @OK=T @Ord={B7}
-> NIL
 
- (box 'any) -> sym
- Creates and returns a new anonymous symbol. The initial value is set to the
anyargument. See alsonewandbox?.
: (show (box '(A B C)))
$134425627 (A B C)
-> $134425627
 
- (box? 'any) -> sym | NIL
- Returns the argument anywhen it is an anonymous symbol,
otherwiseNIL. See alsobox,str?andext?.
: (box? (new))
-> $134563468
: (box? 123)
-> NIL
: (box? 'a)
-> NIL
: (box? NIL)
-> NIL
 
- (bt ['flg]) -> flg
- (Debug mode only) Formatted stack backtrace printing (see trail) for the current point of program
execution. For each bind frame, the function call (reduced withless) ispretty-printed, followed by indented
variable-value-pairs. IfflgisNIL,btthen waits for console input, and terminates when a non-empty line is entered
(likemore). See alsoupandenv.
: (de f (A B)
   (let F 7
      (g (inc A) (dec B)) ) )
-> f
: (de g (C D)
   (let G 8
      (/ C D) ) )
-> g
: (f 2 1)
!? (/ C D)
Div/0
? (bt)
(g (inc A) (dec B))
   C 3
   D 0
   G 8
(f 2 1)
   A 2
   B 1
   F 7
-> NIL
 
- (buf sym 'cnt . prg) -> any
- Creates a temporary local memory buffer on the stack, and binds
symto the pointer during the execution ofprg. The
current value ofsymis saved and restored appropriately. The
return value is the result ofprg. See alsolet,nativeand%@.
(buf Buf BUFSIZ
   (%@ "read" 'I Fd Buf BUFSIZ)
   (%@ "write" 'I Fd2 Buf BUFSIZ) )
 This is functionally equivalent to (but more efficient than)
(let Buf (%@ "malloc" 'P BUFSIZ)
   (%@ "read" 'I Fd Buf BUFSIZ)
   (%@ "write" 'I Fd2 Buf BUFSIZ)
   (%@ "free" NIL Buf) )
 
- (by 'fun1 'fun2 'lst ..) -> lst
- Applies fun1to each element oflst. When
additionallstarguments are given, their elements are also passed
tofun1. Each result offun1is CONSed with its
corresponding argument from the originallst, and collected into a
list which is passed tofun2. For the list returned fromfun2, the CAR elements returned byfun1are
(destructively) removed from each element ("decorate-apply-undecorate" idiom).
: (let (A 1 B 2 C 3) (by val sort '(C A B)))
-> (A B C)
: (by '((N) (bit? 1 N)) group (3 11 6 2 9 5 4 10 12 7 8 1))
-> ((3 11 9 5 7 1) (6 2 4 10 12 8))
 
- (bye ['cnt])
- Executes all pending finallyexpressions, closes all open files, executes theVALof the global
variable*Bye(should be aprg), flushes standard output, and then exits the PicoLisp
interpreter. The process return value iscnt, or 0 if the argument
is missing orNIL.
: (setq *Bye '((println 'OK) (println 'bye)))
-> ((println 'OK) (println 'bye))
: (bye)
OK
bye
$
 
- (byte 'num ['cnt]) -> cnt
- Returns - if the second argument is not given - a byte value (0 .. 255) from
the memory location pointed to by num. Otherwisecntis stored in the memory location and returned. See alsoadr.
: (hex (byte (>> -4 (adr (1)))))
-> "12"                             # Short number '1'
: (hex (byte (>> -4 (adr (2)))))
-> "22"                             # Short number '2'
: (setq P (native "@" "malloc" 'N 8))  # Set pointer to a new buffer
-> 25084048
: (byte P (char "A"))                  # Store byte 'A'
-> 65
: (byte (inc P) (char "B"))            # Store byte 'B'
-> 66
: (byte (+ P 2) (char "C"))            # Store byte 'C'
-> 67
: (byte (+ P 3) 0)                     # Store null byte
-> 0
: (native "@" "strdup" 'S P)           # Read bytes as string
-> "ABC"
: (native "@" "free" 'N P)             # Free buffer
-> 0
 
- (bytes 'any) -> cnt
- Returns the number of bytes anywould occupy in encoded binary
format (as generated bypr). See alsosizeandlength.
: (bytes "abc")
-> 4
: (bytes "äbc")
-> 5
: (bytes 127)
-> 2
: (bytes 128)
-> 3
: (bytes (101 (102) 103))
-> 10
: (bytes (101 102 103 .))
-> 9