- *Fork
- A global variable holding a (possibly empty) prgbody, to be
executed after a call toforkin the
child process.
: (push '*Fork '(off *Tmp))   # Clear '*Tmp' in child process
-> (off *Tmp)
 
- +Fold
- Prefix class for maintaining folded indexes to+Stringrelations. Typically used in
combination with the+Refor+Idxprefix classes. See also+IdxFoldand Database.
(rel nm (+Fold +Idx +String))   # Item Description
...
(rel tel (+Fold +Ref +String))  # Phone number
 
- (fail) -> lst
- Constructs an empty Pilog query, i.e. a query
that will always fail. See also goal.
(dm clr> ()                # Clear query chart in search dialogs
   (query> This (fail)) )
 
- fail/0
- Pilog predicate that always fails. See also
true/0.
: (? (fail))
-> NIL
 
- (fd ['cnt]) -> cnt
- Return the current file descriptor, typically of the closest inoroutchannel. If a second file descriptorcntis given, the current file descriptor is copied to it using adup2()system call. See alsoipidandopid.
: (in "@lib.l" (fd))
-> 3
 
- (fetch 'tree 'any) -> any
- Fetches a value for the key anyfrom a database tree. See alsotreeandstore.
: (fetch (tree 'nr '+Item) 2)
-> {B2}
- (fifo 'var ['any ..]) -> any
- Implements a first-in-first-out structure using a circular list. When called
with anyarguments, they will be concatenated to end of the
structure. Otherwise, the first element is removed from the structure and
returned. See alsoqueue,push,pop,rid,rotandcirc.
: (fifo 'X 1)
-> 1
: (fifo 'X 2 3)
-> 3
: X
-> (3 1 2 .)
: (fifo 'X)
-> 1
: (fifo 'X)
-> 2
: X
-> (3 .)
 
- (file) -> (sym1 sym2 . num) | NIL
- Returns for the current input channel the path name sym1, the
file namesym2, and the current line numbernum. If
the current input channel is not a file,NILis returned. See alsoinfo,inandload.
: (load (pack (car (file)) "localFile.l"))  # Load a file in same directory
 
- (fill 'any ['sym|lst]) -> any
- (fill 'any ['cnt|sym] 'any2) -> any
- Non-destructively fills a pattern any, by substitutingsym, or all symbols inlst, or - if no second argument
is given - each pattern symbol inany(seepat?), with its current value.@itself is not considered a pattern symbol here. In any case, expressions
following the symbol^are evaluated and the results
(destructively) spliced into the result. In the second form, all occurrences of
the second argument are simply replaced byany2. In both cases,
unmodified subexpressions are shared.
See alsomatch.
: (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)
: (fill (1 ^(list 'a 'b 'c) 9))
-> (1 a b c 9)
: (fill (1 ^(+ 2 3) 7))
-> (1 5 7)
: (fill (1 (a (b . 2) c) 3) 'b 7)
-> (1 (a (7 . 2) c) 3)
: (fill (1 (a (b . 2) c) 3) 2 123)
-> (1 (a (b . 123) c) 3)
: (match '(This is @X) '(This is a pen))
-> T
: (fill '(Got ^ @X))
-> (Got a pen)
 
- (filter 'fun 'lst ..) -> lst
- Applies funto each element oflst. When
additionallstarguments are given, their elements are also passed
tofun. Returns a list of all elements oflstwherefunreturned non-NIL. See alsofish,find,pickandextract.
: (filter num? (1 A 2 (B) 3 CDE))
-> (1 2 3)
: (filter < (2 9 3 8 4 7) (5 4 3 9 9 5))
-> (2 8 4)
: (filter and (1 NIL 3 NIL 5) (2 3 4 5 6) (7 8 NIL 1 1))
-> (1 5)
: (filter and (range 1 22) '(NIL NIL T .))
-> (3 6 9 12 15 18 21)
 
- (fin 'any) -> num|sym
- Returns anyif it is an atom, otherwise the CDR of its last
cell. See alsolastandtail.
: (fin 'a)
-> a
: (fin '(a . b))
-> b
: (fin '(a b . c))
-> c
: (fin '(a b c))
-> NIL
 
- (finally exe . prg) -> any
- prgis executed, then- exeis evaluated, and the
result of- prgis returned.- exewill also be evaluated
if- prgdoes not terminate normally due to a runtime error or a call
to- throw. See also- bye,- catch,- quitand- 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 funto successive elements oflstuntil
non-NILis returned. Returns that element (and stores the
non-NILvalue in the global variable@@), orNILiffundid
not return non-NILfor any element oflst. When
additionallstarguments are given, their elements are also passed
tofun. See alsoseek,pick,fullyandfilter.
: (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
 
- (finish . prg) -> exe
- Pushes the expressions in prginto the global*Byein reverse order, to be executed just
before the termination of the PicoLisp interpreter.(finish (foo)
(bar))is equivalent to(push '*Bye '(bar) '(foo))See alsobyeandonce.
: (finish (call "rm" "myfile.tmp"))  # Remove a temporary file
-> (call 'rm "myfile.tmp")
 
- (fish 'fun 'any ['any2] ..) -> lst
- Applies funto each element - and recursively to all sublists -
ofany. Returns a list of all items wherefunreturned
non-NIL. Ifany2is non-NIL, it may be
returned byfunto cause the corresponding item or (sub-)list to be
skipped. When additionalanyarguments are given, they are also
passed tofun. See alsoseek,
See alsofilter.
: (fish atom '((a b) c (d e)))
-> (a b c d e)
: (fish sym? '(a -2 (1 b (-3 c 2)) 3 d -1 7))
-> (a b c d)
: (fish gt0 '(a -2 (1 b (-3 c 2)) 3 d -1 7))
-> (1 2 3 7)
: (fish < '(a -2 (1 b (-3 c 2)) 3 d -1 7) NIL 2)
-> (-2 1 -3 -1)
: (fish
   '((X)
      (if (and (pair X) (=1 (car X)))
         "skip"  # Transient symbol (pointer equal)
         (gt0 X) ) )
   '(a -2 (1 b (-3 c 2)) 3 d -1 7)
   "skip" )
-> (3 7)
: (fish == '(a 1 (b (3 b)) 3) NIL 'b)
-> (b b)
- (flg? 'any) -> flg
- Returns Twhen the argumentanyis eitherNILorT. See alsobool.(flg? X)is equivalent to(or (not X) (=T X)).
: (flg? (= 3 3))
-> T
: (flg? (= 3 4))
-> T
: (flg? (+ 3 4))
-> NIL
 
- (flip 'lst ['cnt]) -> lst
- Returns lst(destructively) reversed. Without the optionalcntargument, the whole list is flipped, otherwise only the firstcntelements. See alsoreverseandrot.
: (flip (1 2 3 4))         # Flip all  four elements
-> (4 3 2 1)
: (flip (1 2 3 4 5 6) 3)   # Flip only the first three elements
-> (3 2 1 4 5 6)
 
- (flood 'lst1 'fun 'lst2) -> lst
- Implements a flooding algorithm, returning a list of flooded nodes of a
graph. lst1is a list of relevant nodes,funa
function accepting a node and returning a list of connected nodes, andlst2a list of seed nodes.
(load "@lib/simul.l")
: (setq *Graph (1 2 3 4 5))         # For simplicity, a one-dimensional "graph"
-> (1 2 3 4 5)
: (simul~flood
   (maplist prog *Graph)            # List of relevant cells
   '((X)                            # Flood the three central cells (2 3 4)
      (when (member (car X) (2 3))  # 2 -> 3 and 3 -> 4
         (list (cdr X)) ) )
   (list (cddr *Graph)) )           # Seed third (middle) cell
-> ((3 4 5) (2 3 4 5) (4 5))        # -> Cells (3 ..) (2 ..) (4 ..)
- (flush) -> flg
- Flushes the current output stream by writing all buffered data. A call to
flushfor standard output is done automatically before a call tokey. ReturnsTwhen
successful. See alsorewind.
: (flush)
-> T
 
- (fold 'any ['cnt]) -> sym
- Folding to a canonical form: If anyis not a symbol, it is
returned as it is. Otherwise, a new transient symbol with all digits and all
letters ofany, converted to lower case, is returned. If thecntargument is given and non-zero, the result is truncated to that
length. See alsolowc.
: (fold " 1A 2-b/3")
-> "1a2b3"
: (fold " 1A 2-B/3" 3)
-> "1a2"
 
- fold/3
- Pilog predicate that succeeds if the first
argument, after folding it to a
canonical form, is a prefix of the folded string representation of the
result of applying thegetalgorithm to
the following arguments. Typically used as filter predicate inselect/3database queries. See alsopre?,isa/2,same/3,bool/3,range/3,head/3,part/3andtolr/3.
: (?
   @Nr (1 . 5)
   @Nm "main"
   (select (@Item)
      ((nr +Item @Nr) (nm +Item @Nm))
      (range @Nr @Item nr)
      (fold @Nm @Item nm) ) )
 @Nr=(1 . 5) @Nm="main" @Item={B1}
-> NIL
- (for sym 'num ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any
- (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 ofsymis saved,symis
bound to1, and the body is executed with increasing values up to
(and including)num.
 In the second form, the value ofsymis saved,symis
subsequently bound to the elements oflst, and the body is executed
each time.
 In the third form, the value ofsymis saved, andsymis bound toany1. Ifsym2is given, it is treated as a
counter variable, first bound to 1 and then incremented for each execution of
the body. While the conditionany2evaluates to
non-NIL, the body is repeatedly executed and, ifprgis given,symis re-bound to the result of its evaluation.
 If a clause hasNILorTas its CAR, the clause's
second element is evaluated as a condition and - if the result isNILor non-NIL, respectively - theprgis
executed and the result returned. If the body is never executed,NILis returned.
 See alsodoandloop.
# First form:
: (for N 5 (printsp N))
1 2 3 4 5 -> 5
: (for N 5 (printsp N) (NIL (< N 3) (printsp 'enough)))
1 2 3 enough -> enough
: (for N 5 (T (> N 3) (printsp 'enough)) (printsp N))
1 2 3 enough -> enough
# Second form:
: (for X (1 a 2 b) (printsp X))
1 a 2 b -> b
: (for (I . X) '(a b c) (println I X))
1 a
2 b
3 c
-> c
# Third form:
: (for (L (1 2 3 4 5) L) (printsp (pop 'L)))
1 2 3 4 5 -> 5
: (for (N 1 (>= 5 N) (inc N)) (printsp N))
1 2 3 4 5 -> 5
: (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/2
- for/3
- for/4
- Pilog predicate that generates a sequence of
numbers. See also forandrange.
: (? (for @I 3))
 @I=1
 @I=2
 @I=3
-> NIL
: (? (for @I 3 7))
 @I=3
 @I=4
 @I=5
 @I=6
 @I=7
-> NIL
: (? (for @I 7 3 2))
 @I=7
 @I=5
 @I=3
-> NIL
: (? (for @N T))
 @N=1
 @N=2
 @N=3
 ...
 
- (forall 'cls . prg) -> any
- (forall '(cnt . cls) . prg) -> any
- Runs prgon all database objects of the classcls,
as given by thedbsdefinition. In the
second form, thecnt'th database file is used instead. The global
variableThisis bound to each object.
See alsoseqandcollect.
: (forall '+Item (println (: nr) (: nm)))
1 "Main Part"
2 "Spare Part"
3 "Auxiliary Construction"
4 "Enhancement Additive"
5 "Metal Fittings"
6 "Gadget Appliance"
 
- (fork) -> pid | NIL
- Forks a child process. Returns NILin the child, and the
child's process IDpidin the parent. In the child, theVALof the global variable*Fork(should be aprg) is
executed. See alsoexec,detach,kids,pipeandtell.
: (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|lst ['cnt ['sym1 ['sym2]]]) -> num
- Converts a number numto a string, or a stringsym|lstto a number. In both cases, optionally a precisioncnt, a decimal-separatorsym1and a
thousands-separatorsym2can be supplied. ReturnsNILif the conversion is unsuccessful. See also Numbers,pad,hex,oct,binandround.
: (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 (1 "23" (4 5 6)))
-> 123456
: (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
symbolsym(i.e. the first symbol greater than any symbol in the
database), and the listlstof free symbols. See alsoseq,zapanddbck.
: (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 anyis
found, and starts subsequent reading from that point. The foundanyargument (orNILif none is found) is returned. See alsotillandecho.
: (and (from "val='") (till "'" T))
test val='abc'
-> "abc"
 
- (full 'any) -> bool
- Returns NILifanyis a non-empty list with at
least oneNILelement, otherwiseT.(full
X)is equivalent to(not (memq NIL X)). See alsofully.
: (full (1 2 3))
-> T
: (full (1 NIL 3))
-> NIL
: (full 123)
-> T
 
- (fully 'fun 'lst ..) -> flg
- Applies funto successive elements oflst, and
returnsNILimmediately if one of the results isNIL.
Otherwise,Tis returned. When additionallstarguments are given, their elements are also passed tofun.(fully foo Lst)is equivalent to(not (find '((X) (not (foo
X))) Lst)). See alsofindandfull.
: (fully gt0 (1 2 3))
-> T
: (fully gt0 (1 -2 3))
-> NIL
 
- (fun 'fun ['any ..]) -> any
- Applies funto theanyarguments.(fun foo
'args)is equivalent to(foo 'args), and(fun (expr)
'args)is equivalent to((expr) 'args). See alsoapplyandpass.
: (find fun '(sym? ((X) (> X 3)) num?) 'a)
-> sym?
: (find fun '(sym? ((X) (> X 3)) num?) 3)
-> num?
: (find fun '(sym? ((X) (> X 3)) num?) 4)
-> ((X) (> X 3))
 
- (fun? 'any) -> any
- Returns NILwhen the argumentanyis 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,Tfor a function without arguments, and a single formal parameter or a list of
formal parameters for a function. See alsogetd.
: (fun? 1000000000)              # Might be a code pointer
-> 1000000000
: (fun? 10000000000000000000)    # Too big for a code pointer
-> 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