picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

refP.html (29181B)


      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">
      2 <html lang="en">
      3 <head>
      4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      5 <title>P</title>
      6 <link rel="stylesheet" href="doc.css" type="text/css">
      7 </head>
      8 <body>
      9 
     10 <h1>P</h1>
     11 
     12 <dl>
     13 
     14 <dt><a name="*PPid"><code>*PPid</code></a>
     15 <dd>A global constant holding the process-id of the parent picolisp process, or
     16 <code>NIL</code> if the current process is a top level process.
     17 
     18 <pre><code>
     19 : (println *PPid *Pid)
     20 NIL 5286
     21 
     22 : (unless (fork) (println *PPid *Pid) (bye))
     23 5286 5522
     24 </code></pre>
     25 
     26 <dt><a name="*Pid"><code>*Pid</code></a>
     27 <dd>A global constant holding the current process-id.
     28 
     29 <pre><code>
     30 : *Pid
     31 -> 6386
     32 : (call "ps")  # Show processes
     33   PID TTY          TIME CMD
     34  .... ...      ........ .....
     35  6386 pts/1    00:00:00 pil   # <- current process
     36  6388 pts/1    00:00:00 ps
     37 -> T
     38 </code></pre>
     39 
     40 <dt><a name="*Prompt"><code>*Prompt</code></a>
     41 <dd>Global variable holding a (possibly empty) <code>prg</code> body, which is
     42 executed - and the result <code><a href="refP.html#prin">prin</a></code>ted -
     43 every time before a prompt is output to the console in the
     44 "read-eval-print-loop" (REPL).
     45 
     46 <pre><code>
     47 : (de *Prompt (pack "[" (stamp) "]"))
     48 # *Prompt redefined
     49 -> *Prompt
     50 [2011-10-11 16:50:05]: (+ 1 2 3)
     51 -> 6
     52 [2011-10-11 16:50:11]:
     53 </code></pre>
     54 
     55 <dt><a name="pack"><code>(pack 'any ..) -> sym</code></a>
     56 <dd>Returns a transient symbol whose name is concatenated from all arguments
     57 <code>any</code>. A <code>NIL</code> arguments contributes nothing to the result
     58 string, a number is converted to a digit string, a symbol supplies the
     59 characters of its name, and for a list its elements are taken. See also <code><a
     60 href="refT.html#text">text</a></code> and <code><a
     61 href="refG.html#glue">glue</a></code>.
     62 
     63 <pre><code>
     64 : (pack 'car " is " 1 '(" symbol " name))
     65 -> "car is 1 symbol name"
     66 </code></pre>
     67 
     68 <dt><a name="pad"><code>(pad 'cnt 'any) -> sym</code></a>
     69 <dd>Returns a transient symbol with <code>any</code> <code><a
     70 href="refP.html#pack">pack</a></code>ed with leading '0' characters, up to a
     71 field width of <code>cnt</code>. See also <code><a
     72 href="refF.html#format">format</a></code> and <code><a
     73 href="refA.html#align">align</a></code>.
     74 
     75 <pre><code>
     76 : (pad 5 1)
     77 -> "00001"
     78 : (pad 5 123456789)
     79 -> "123456789"
     80 </code></pre>
     81 
     82 <dt><a name="pair"><code>(pair 'any) -> any</code></a>
     83 <dd>Returns <code>any</code> when the argument is a cons pair. See also <code><a
     84 href="refA.html#atom">atom</a></code> and <code><a
     85 href="refL.html#lst?">lst?</a></code>.
     86 
     87 <pre><code>
     88 : (pair NIL)
     89 -> NIL
     90 : (pair (1 . 2))
     91 -> (1 . 2)
     92 : (pair (1 2 3))
     93 -> (1 2 3)
     94 </code></pre>
     95 
     96 <dt><a name="part/3"><code>part/3</code></a>
     97 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the first
     98 argument, after <code><a href="refF.html#fold">fold</a></code>ing it to a
     99 canonical form, is a <i>substring</i> of the folded string representation of the
    100 result of applying the <code><a href="refG.html#get">get</a></code> algorithm to
    101 the following arguments. Typically used as filter predicate in <code><a
    102 href="refS.html#select/3">select/3</a></code> database queries. See also
    103 <code><a href="refS.html#sub?">sub?</a></code>, <code><a
    104 href="refI.html#isa/2">isa/2</a></code>, <code><a
    105 href="refS.html#same/3">same/3</a></code>, <code><a
    106 href="refB.html#bool/3">bool/3</a></code>, <code><a
    107 href="refR.html#range/3">range/3</a></code>, <code><a
    108 href="refH.html#head/3">head/3</a></code>, <code><a
    109 href="refF.html#fold/3">fold/3</a></code> and <code><a
    110 href="refT.html#tolr/3">tolr/3</a></code>.
    111 
    112 <pre><code>
    113 : (?
    114    @Nr (1 . 5)
    115    @Nm "part"
    116    (select (@Item)
    117       ((nr +Item @Nr) (nm +Item @Nm))
    118       (range @Nr @Item nr)
    119       (part @Nm @Item nm) ) )
    120  @Nr=(1 . 5) @Nm="part" @Item={3-1}
    121  @Nr=(1 . 5) @Nm="part" @Item={3-2}
    122 -> NIL
    123 </code></pre>
    124 
    125 <dt><a name="pass"><code>(pass 'fun ['any ..]) -> any</code></a>
    126 <dd>Passes to <code>fun</code> all arguments <code>any</code>, and all remaining
    127 variable arguments (<code>@</code>) as they would be returned by <code><a
    128 href="refR.html#rest">rest</a></code>. <code>(pass 'fun 'any)</code> is
    129 equivalent to <code>(apply 'fun (rest) 'any)</code>. See also <code><a
    130 href="refA.html#apply">apply</a></code>.
    131 
    132 <pre><code>
    133 : (de bar (A B . @)
    134    (println 'bar A B (rest)) )
    135 -> bar
    136 : (de foo (A B . @)
    137    (println 'foo A B)
    138    (pass bar 1)
    139    (pass bar 2) )
    140 -> foo
    141 : (foo 'a 'b 'c 'd 'e 'f)
    142 foo a b
    143 bar 1 c (d e f)
    144 bar 2 c (d e f)
    145 -> (d e f)
    146 </code></pre>
    147 
    148 <dt><a name="pat?"><code>(pat? 'any) -> pat | NIL</code></a>
    149 <dd>Returns <code>any</code> when the argument <code>any</code> is a symbol
    150 whose name starts with an at-mark "<code>@</code>", otherwise <code>NIL</code>.
    151 
    152 <pre><code>
    153 : (pat? '@)
    154 -> @
    155 : (pat? "@Abc")
    156 -> "@Abc"
    157 : (pat? "ABC")
    158 -> NIL
    159 : (pat? 123)
    160 -> NIL
    161 </code></pre>
    162 
    163 <dt><a name="patch"><code>(patch 'lst 'any . prg) -> any</code></a>
    164 <dd>Destructively replaces all sub-expressions of <code>lst</code>, that
    165 <code><a href="refM.html#match">match</a></code> the pattern <code>any</code>,
    166 by the result of the execution of <code>prg</code>. See also <code><a
    167 href="refD.html#daemon">daemon</a></code> and <code><a
    168 href="refR.html#redef">redef</a></code>.
    169 
    170 <pre><code>
    171 : (pp 'hello)
    172 (de hello NIL
    173    (prinl "Hello world!") )
    174 -> hello
    175 
    176 : (patch hello 'prinl 'println)
    177 -> NIL
    178 : (pp 'hello)
    179 (de hello NIL
    180    (println "Hello world!") )
    181 -> hello
    182 
    183 : (patch hello '(prinl @S) (fill '(println "We said: " . @S)))
    184 -> NIL
    185 : (hello)
    186 We said: Hello world!
    187 -> "Hello world!"
    188 </code></pre>
    189 
    190 <dt><a name="path"><code>(path 'any) -> sym</code></a>
    191 <dd>Substitutes any leading "<code>@</code>" character in the <code>any</code>
    192 argument with the <u>PicoLisp Home Directory</u>, as it was remembered during
    193 interpreter startup. Optionally, the name may be preceded by a "<code>+</code>"
    194 character (as used by <code><a href="refI.html#in">in</a></code> and <code><a
    195 href="refO.html#out">out</a></code>). This mechanism is used internally by all
    196 I/O functions. See also <a href="ref.html#invoc">Invocation</a>, <code><a
    197 href="refB.html#basename">basename</a></code> and <code><a
    198 href="refD.html#dirname">dirname</a></code>.
    199 
    200 <pre><code>
    201 $ /usr/bin/picolisp /usr/lib/picolisp/lib.l
    202 : (path "a/b/c")
    203 -> "a/b/c"
    204 : (path "@a/b/c")
    205 -> "/usr/lib/picolisp/a/b/c"
    206 : (path "+@a/b/c")
    207 -> "+/usr/lib/picolisp/a/b/c"
    208 </code></pre>
    209 
    210 <dt><a name="peek"><code>(peek) -> sym</code></a>
    211 <dd>Single character look-ahead: Returns the same character as the next call to
    212 <code><a href="refC.html#char">char</a></code> would return. See also <code><a
    213 href="refS.html#skip">skip</a></code>.
    214 
    215 <pre><code>
    216 $ cat a
    217 # Comment
    218 abcd
    219 $ pil +
    220 : (in "a" (list (peek) (char)))
    221 -> ("#" "#")
    222 </code></pre>
    223 
    224 <dt><a name="permute/2"><code>permute/2</code></a>
    225 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the second
    226 argument is a permutation of the list in the second argument. See also <code><a
    227 href="refA.html#append/3">append/3</a></code>.
    228 
    229 <pre><code>
    230 : (? (permute (a b c) @X))
    231  @X=(a b c)
    232  @X=(a c b)
    233  @X=(b a c)
    234  @X=(b c a)
    235  @X=(c a b)
    236  @X=(c b a)
    237 -> NIL
    238 </code></pre>
    239 
    240 <dt><a name="pick"><code>(pick 'fun 'lst ..) -> any</code></a>
    241 <dd>Applies <code>fun</code> to successive elements of <code>lst</code> until
    242 non-<code>NIL</code> is returned. Returns that value, or <code>NIL</code> if
    243 <code>fun</code> did not return non-<code>NIL</code> for any element of
    244 <code>lst</code>. When additional <code>lst</code> arguments are given, their
    245 elements are also passed to <code>fun</code>. <code>(pick 'fun 'lst)</code> is
    246 equivalent to <code>(fun (find 'fun 'lst))</code>. See also <code><a
    247 href="refS.html#seek">seek</a></code>, <code><a
    248 href="refF.html#find">find</a></code> and <code><a
    249 href="refE.html#extract">extract</a></code>.
    250 
    251 <pre><code>
    252 : (setq A NIL  B 1  C NIL  D 2  E NIL  F 3)
    253 -> 3
    254 : (find val '(A B C D E))
    255 -> B
    256 : (pick val '(A B C D E))
    257 -> 1
    258 </code></pre>
    259 
    260 <dt><a name="pico"><code>pico</code></a>
    261 <dd>(64-bit version only) A global constant holding the initial (default)
    262 namespace of internal symbols. Its value is a cons pair of two '<code><a
    263 href="refI.html#idx">idx</a></code>' trees, one for symbols with short names and
    264 one for symbols with long names (more than 7 bytes in the name). See also
    265 <code><a href="refS.html#symbols">symbols</a></code>, <code><a
    266 href="refI.html#import">import</a></code> and <code><a
    267 href="refI.html#intern">intern</a></code>.
    268 
    269 <pre><code>
    270 : (symbols)
    271 -> pico
    272 : (cdr pico)
    273 -> (rollback (*NoTrace (ledSearch (expandTab (********)) *CtryCode ...
    274 </code></pre>
    275 
    276 <dt><a name="pil"><code>(pil ['any ..]) -> sym</code></a>
    277 <dd>Returns the path name to the <code><a
    278 href="refP.html#pack">pack</a></code>ed <code>any</code> arguments in
    279 the directory ".pil/" in the user's home directory.
    280 See also <code><a href="refT.html#tmp">tmp</a></code>.
    281 
    282 <pre><code>
    283 : (pil "history")  # Path to the line editor's history file
    284 -> "/home/app/.pil/history"
    285 </code></pre>
    286 
    287 <dt><a name="pilog"><code>(pilog 'lst . prg) -> any</code></a>
    288 <dd>Evaluates a <a href="ref.html#pilog">Pilog</a> query, and executes
    289 <code>prg</code> for each result set with all Pilog variables bound to their
    290 matching values. See also <code><a href="refS.html#solve">solve</a></code>,
    291 <code><a href="ref_.html#?">?</a></code>, <code><a
    292 href="refG.html#goal">goal</a></code> and <code><a
    293 href="refP.html#prove">prove</a></code>.
    294 
    295 <pre><code>
    296 : (pilog '((append @X @Y (a b c))) (println @X '- @Y))
    297 NIL - (a b c)
    298 (a) - (b c)
    299 (a b) - (c)
    300 (a b c) - NIL
    301 -> NIL
    302 </code></pre>
    303 
    304 <dt><a name="pipe"><code>(pipe exe) -> cnt</code></a>
    305 <dt><code>(pipe exe . prg) -> any</code>
    306 <dd>Executes <code>exe</code> in a <code><a
    307 href="refF.html#fork">fork</a></code>'ed child process (which terminates
    308 thereafter). In the first form, <code>pipe</code> just returns a file descriptor
    309 to read from the standard output of that process. In the second form, it opens
    310 the standard output of that process as input channel during the execution of
    311 <code>prg</code>. The current input channel will be saved and restored
    312 appropriately. See also <code><a href="refL.html#later">later</a></code>,
    313 <code><a href="refI.html#ipid">ipid</a></code>, <code><a
    314 href="refI.html#in">in</a></code> and <code><a
    315 href="refO.html#out">out</a></code>.
    316 
    317 <pre><code>
    318 : (pipe                                # equivalent to 'any'
    319    (prinl "(a b # Comment^Jc d)")         # (child process)
    320    (read) )                               # (parent process)
    321 -> (a b c d)
    322 : (pipe                                # pipe through an external program
    323    (out '(tr "[a-z]" "[A-Z]")             # (child process)
    324       (prinl "abc def ghi") )
    325    (line T) )                             # (parent process)
    326 -> "ABC DEF GHI"
    327 </code></pre>
    328 
    329 <dt><a name="place"><code>(place 'cnt 'lst 'any) -> lst</code></a>
    330 <dd>Places <code>any</code> into <code>lst</code> at position <code>cnt</code>.
    331 This is a non-destructive operation. See also <code><a
    332 href="refI.html#insert">insert</a></code>, <code><a
    333 href="refR.html#remove">remove</a></code>, <code><a
    334 href="refA.html#append">append</a></code>, <code><a
    335 href="refD.html#delete">delete</a></code> and <code><a
    336 href="refR.html#replace">replace</a></code>.
    337 
    338 <pre><code>
    339 : (place 3 '(a b c d e) 777)
    340 -> (a b 777 d e)
    341 : (place 1 '(a b c d e) 777)
    342 -> (777 b c d e)
    343 : (place 9 '(a b c d e) 777)
    344 -> (a b c d e 777)
    345 </code></pre>
    346 
    347 <dt><a name="poll"><code>(poll 'cnt) -> cnt | NIL</code></a>
    348 <dd>Checks for the availability of data for reading on the file descriptor
    349 <code>cnt</code>. See also <code><a href="refO.html#open">open</a></code>,
    350 <code><a href="refI.html#in">in</a></code> and <code><a
    351 href="refC.html#close">close</a></code>.
    352 
    353 <pre><code>
    354 : (and (poll *Fd) (in @ (read)))  # Prevent blocking
    355 </code></pre>
    356 
    357 <dt><a name="pool"><code>(pool ['sym1 ['lst] ['sym2] ['sym3]]) -> T</code></a>
    358 <dd>Opens the file <code>sym1</code> as a database file in read/write mode. If
    359 the file does not exist, it is created. A currently open database is closed.
    360 <code>lst</code> is a list of block size scale factors (i.e. numbers),
    361 defaulting to (2) (for a single file with a 256 byte block size). If
    362 <code>lst</code> is given, an individual database file is opened for each item.
    363 If <code>sym2</code> is non-<code>NIL</code>, it is opened in append-mode as an
    364 asynchronous replication journal. If <code>sym3</code> is non-<code>NIL</code>,
    365 it is opened for reading and appending, to be used as a synchronous transaction
    366 log during <code><a href="refC.html#commit">commit</a></code>s. See also
    367 <code><a href="refD.html#dbs">dbs</a></code>, <code><a
    368 href="refD.html#*Dbs">*Dbs</a></code> and <code><a
    369 href="refJ.html#journal">journal</a></code>.
    370 
    371 <pre><code>
    372 : (pool "/dev/hda2")
    373 -> T
    374 
    375 : *Dbs
    376 -> (1 2 2 4)
    377 : (pool "dbFile" *Dbs)
    378 -> T
    379 :
    380 abu:~/pico  ls -l dbFile*
    381 -rw-r--r-- 1 abu abu 256 2007-06-11 07:57 dbFile1
    382 -rw-r--r-- 1 abu abu  13 2007-06-11 07:57 dbFile2
    383 -rw-r--r-- 1 abu abu  13 2007-06-11 07:57 dbFile3
    384 -rw-r--r-- 1 abu abu  13 2007-06-11 07:57 dbFile4
    385 </code></pre>
    386 
    387 <dt><a name="pop"><code>(pop 'var) -> any</code></a>
    388 <dd>Pops the first element (CAR) from the stack in <code>var</code>. See also
    389 <code><a href="refP.html#push">push</a></code>, <code><a
    390 href="refQ.html#queue">queue</a></code>, <code><a
    391 href="refC.html#cut">cut</a></code>, <code><a
    392 href="refD.html#del">del</a></code> and <code><a
    393 href="refF.html#fifo">fifo</a></code>.
    394 
    395 <pre><code>
    396 : (setq S '((a b c) (1 2 3)))
    397 -> ((a b c) (1 2 3))
    398 : (pop S)
    399 -> a
    400 : (pop (cdr S))
    401 -> 1
    402 : (pop 'S)
    403 -> (b c)
    404 : S
    405 -> ((2 3))
    406 </code></pre>
    407 
    408 <dt><a name="port"><code>(port ['T] 'cnt|(cnt . cnt) ['var]) -> cnt</code></a>
    409 <dd>Opens a TCP-Port <code>cnt</code> (or a UDP-Port if the first argument is
    410 <code>T</code>), and returns a socket descriptor suitable as an argument for
    411 <code><a href="refL.html#listen">listen</a></code> or <code><a
    412 href="refA.html#accept">accept</a></code> (or <code><a
    413 href="refU.html#udp">udp</a></code>, respectively). If <code>cnt</code> is zero,
    414 some free port number is allocated. If a pair of <code>cnt</code>s is given
    415 instead, it should be a range of numbers which are tried in turn. When
    416 <code>var</code> is given, it is bound to the port number.
    417 
    418 <pre><code>
    419 : (port 0 'A)                       # Allocate free port
    420 -> 4
    421 : A
    422 -> 1034                             # Got 1034
    423 : (port (4000 . 4008) 'A)           # Try one of these ports
    424 -> 5
    425 : A
    426 -> 4002
    427 </code></pre>
    428 
    429 <dt><a name="pp"><code>(pp 'sym) -> sym</code></a>
    430 <dt><code>(pp 'sym 'cls) -> sym</code>
    431 <dt><code>(pp '(sym . cls)) -> sym</code>
    432 <dd>Pretty-prints the function or method definition of <code>sym</code>. The
    433 output format would regenerate that same definition when read and executed. See
    434 also <code><a href="refP.html#pretty">pretty</a></code>, <code><a
    435 href="refD.html#debug">debug</a></code> and <code><a
    436 href="refV.html#vi">vi</a></code>.
    437 
    438 <pre><code>
    439 : (pp 'tab)
    440 (de tab (Lst . @)
    441    (for N Lst
    442       (let V (next)
    443          (and (gt0 N) (space (- N (length V))))
    444          (prin V)
    445          (and
    446             (lt0 N)
    447             (space (- 0 N (length V))) ) ) )
    448    (prinl) )
    449 -> tab
    450 
    451 : (pp 'has> '+Entity)
    452 (dm has> (Var Val)
    453    (or
    454       (nor Val (get This Var))
    455       (has> (meta This Var) Val (get This Var)) ) )
    456 -> has>
    457 
    458 : (more (can 'has>) pp)
    459 (dm (has> . +relation) (Val X)
    460    (and (= Val X) X) )
    461 
    462 (dm (has> . +Fold) (Val X)
    463    (extra
    464       Val
    465       (if (= Val (fold Val)) (fold X) X) ) )
    466 
    467 (dm (has> . +Entity) (Var Val)
    468    (or
    469       (nor Val (get This Var))
    470       (has> (meta This Var) Val (get This Var)) ) )
    471 
    472 (dm (has> . +List) (Val X)
    473    (and
    474       Val
    475       (or
    476          (extra Val X)
    477          (find '((X) (extra Val X)) X) ) ) )
    478 
    479 (dm (has> . +Bag) (Val X)
    480    (and
    481       Val
    482       (or (super Val X) (car (member Val X))) ) )
    483 </code></pre>
    484 
    485 <dt><a name="pr"><code>(pr 'any ..) -> any</code></a>
    486 <dd>Binary print: Prints all <code>any</code> arguments to the current output
    487 channel in encoded binary format. See also <code><a
    488 href="refR.html#rd">rd</a></code>, <code><a
    489 href="refB.html#bytes">bytes</a></code>, <code><a
    490 href="refT.html#tell">tell</a></code>, <code><a
    491 href="refH.html#hear">hear</a></code> and <code><a
    492 href="refW.html#wr">wr</a></code>.
    493 
    494 <pre><code>
    495 : (out "x" (pr 7 "abc" (1 2 3) 'a))  # Print to "x"
    496 -> a
    497 : (hd "x")
    498 00000000  04 0E 0E 61 62 63 01 04 02 04 04 04 06 03 05 61  ...abc.........a
    499 -> NIL
    500 </code></pre>
    501 
    502 <dt><a name="prEval"><code>(prEval 'prg ['cnt]) -> any</code></a>
    503 <dd>Executes <code>prg</code>, similar to <code><a
    504 href="refR.html#run">run</a></code>, by evaluating all expressions in
    505 <code>prg</code> (within the binding environment given by <code>cnt-1</code>).
    506 As a side effect, all atomic expressions will be printed with <code><a
    507 href="refP.html#prinl">prinl</a></code>. See also <code><a
    508 href="refE.html#eval">eval</a></code>.
    509 
    510 <pre><code>
    511 : (let Prg 567
    512    (prEval
    513       '("abc" (prinl (+ 1 2 3)) Prg 987) ) )
    514 abc
    515 6
    516 567
    517 987
    518 -> 987
    519 </code></pre>
    520 
    521 <dt><a name="pre?"><code>(pre? 'any1 'any2) -> any2 | NIL</code></a>
    522 <dd>Returns <code>any2</code> when the string representation of
    523 <code>any1</code> is a prefix of the string representation of <code>any2</code>.
    524 See also <code><a href="refS.html#sub?">sub?</a></code>.
    525 
    526 <pre><code>
    527 : (pre? "abc" "abcdef")
    528 -> "abcdef"
    529 : (pre? "def" "abcdef")
    530 -> NIL
    531 : (pre? (+ 3 4) "7fach")
    532 -> "7fach"
    533 : (pre? NIL "abcdef")
    534 -> "abcdef"
    535 </code></pre>
    536 
    537 <dt><a name="pretty"><code>(pretty 'any 'cnt)</code></a>
    538 <dd>Pretty-prints <code>any</code>. If <code>any</code> is an atom, or a list
    539 with a <code><a href="refS.html#size">size</a></code> not greater than 12, it is
    540 <code><a href="refP.html#print">print</a></code>ed as is. Otherwise, only the
    541 opening parenthesis and the CAR of the list is printed, all other elementes are
    542 pretty-printed recursively indented by three spaces, followed by a space and the
    543 corresponding closing parenthesis. The initial indentation level
    544 <code>cnt</code> defaults to zero. See also <code><a
    545 href="refP.html#pp">pp</a></code>.
    546 
    547 <pre><code>
    548 : (pretty '(a (b c d) (e (f (g) (h) (i)) (j (k) (l) (m))) (n o p) q))
    549 (a
    550    (b c d)
    551    (e
    552       (f (g) (h) (i))
    553       (j (k) (l) (m)) )
    554    (n o p)
    555    q )-> ")"
    556 </code></pre>
    557 
    558 <dt><a name="prin"><code>(prin 'any ..) -> any</code></a>
    559 <dd>Prints the string representation of all <code>any</code> arguments to the
    560 current output channel. No space or newline is printed between individual items,
    561 or after the last item. For lists, all elements are <code>prin</code>'ted
    562 recursively. See also <code><a href="refP.html#prinl">prinl</a></code>.
    563 
    564 <pre><code>
    565 : (prin 'abc 123 '(a 1 b 2))
    566 abc123a1b2-> (a 1 b 2)
    567 </code></pre>
    568 
    569 <dt><a name="prinl"><code>(prinl 'any ..) -> any</code></a>
    570 <dd>Prints the string representation of all <code>any</code> arguments to the
    571 current output channel, followed by a newline. No space or newline is printed
    572 between individual items. For lists, all elements are <code>prin</code>'ted
    573 recursively. See also <code><a href="refP.html#prin">prin</a></code>.
    574 
    575 <pre><code>
    576 : (prinl 'abc 123 '(a 1 b 2))
    577 abc123a1b2
    578 -> (a 1 b 2)
    579 </code></pre>
    580 
    581 <dt><a name="print"><code>(print 'any ..) -> any</code></a>
    582 <dd>Prints all <code>any</code> arguments to the current output channel. If
    583 there is more than one argument, a space is printed between successive
    584 arguments. No space or newline is printed after the last item. See also <code><a
    585 href="refP.html#println">println</a></code>, <code><a
    586 href="refP.html#printsp">printsp</a></code>, <code><a
    587 href="refS.html#sym">sym</a></code> and <code><a
    588 href="refS.html#str">str</a></code>
    589 
    590 <pre><code>
    591 : (print 123)
    592 123-> 123
    593 : (print 1 2 3)
    594 1 2 3-> 3
    595 : (print '(a b c) 'def)
    596 (a b c) def-> def
    597 </code></pre>
    598 
    599 <dt><a name="println"><code>(println 'any ..) -> any</code></a>
    600 <dd>Prints all <code>any</code> arguments to the current output channel,
    601 followed by a newline. If there is more than one argument, a space is printed
    602 between successive arguments. See also <code><a
    603 href="refP.html#print">print</a></code>, <code><a
    604 href="refP.html#printsp">printsp</a></code>.
    605 
    606 <pre><code>
    607 : (println '(a b c) 'def)
    608 (a b c) def
    609 -> def
    610 </code></pre>
    611 
    612 <dt><a name="printsp"><code>(printsp 'any ..) -> any</code></a>
    613 <dd>Prints all <code>any</code> arguments to the current output channel,
    614 followed by a space. If there is more than one argument, a space is printed
    615 between successive arguments. See also <code><a
    616 href="refP.html#print">print</a></code>, <code><a
    617 href="refP.html#println">println</a></code>.
    618 
    619 <pre><code>
    620 : (printsp '(a b c) 'def)
    621 (a b c) def -> def
    622 </code></pre>
    623 
    624 <dt><a name="prior"><code>(prior 'lst1 'lst2) -> lst | NIL</code></a>
    625 <dd>Returns the cell in <code>lst2</code> which immediately precedes the cell
    626 <code>lst1</code>, or <code>NIL</code> if <code>lst1</code> is not found in
    627 <code>lst2</code> or is the very first cell. <code><a
    628 href="ref_.html#==">==</a></code> is used for comparison (pointer equality). See
    629 also <code><a href="refO.html#offset">offset</a></code> and <code><a
    630 href="refM.html#memq">memq</a></code>.
    631 
    632 <pre><code>
    633 : (setq L (1 2 3 4 5 6))
    634 -> (1 2 3 4 5 6)
    635 : (setq X (cdddr L))
    636 -> (4 5 6)
    637 : (prior X L)
    638 -> (3 4 5 6)
    639 </code></pre>
    640 
    641 <dt><a name="proc"><code>(proc 'sym ..) -> T</code></a>
    642 <dd>(Debug mode only) Shows a list of processes with command names given by the
    643 <code>sym</code> arguments, using the system <code>ps</code> utility. See also
    644 <code><a href="refH.html#hd">hd</a></code>.
    645 
    646 <pre><code>
    647 : (proc 'pil)
    648   PID  PPID  STARTED  SIZE %CPU WCHAN  CMD
    649 16993  3267 12:38:21  1516  0.5 -      /usr/bin/picolisp /usr/lib/picolisp/lib.l /usr/bin/pil +
    650 15731  1834 12:36:35  2544  0.1 -      /usr/bin/picolisp /usr/lib/picolisp/lib.l /usr/bin/pil app/main.l -main -go +
    651 15823 15731 12:36:44  2548  0.0 -        /usr/bin/picolisp /usr/lib/picolisp/lib.l /usr/bin/pil app/main.l -main -go +
    652 -> T
    653 </code></pre>
    654 
    655 <dt><a name="prog"><code>(prog . prg) -> any</code></a>
    656 <dd>Executes <code>prg</code>, and returns the result of the last expression.
    657 See also <code><a href="refN.html#nil">nil</a></code>, <code><a
    658 href="refT.html#t">t</a></code>, <code><a
    659 href="refP.html#prog1">prog1</a></code> and <code><a
    660 href="refP.html#prog2">prog2</a></code>.
    661 
    662 <pre><code>
    663 : (prog (print 1) (print 2) (print 3))
    664 123-> 3
    665 </code></pre>
    666 
    667 <dt><a name="prog1"><code>(prog1 'any1 . prg) -> any1</code></a>
    668 <dd>Executes all arguments, and returns the result of the first expression
    669 <code>any1</code>. See also <code><a href="refN.html#nil">nil</a></code>,
    670 <code><a href="refT.html#t">t</a></code>, <code><a
    671 href="refP.html#prog">prog</a></code> and <code><a
    672 href="refP.html#prog2">prog2</a></code>.
    673 
    674 <pre><code>
    675 : (prog1 (print 1) (print 2) (print 3))
    676 123-> 1
    677 </code></pre>
    678 
    679 <dt><a name="prog2"><code>(prog2 'any1 'any2 . prg) -> any2</code></a>
    680 <dd>Executes all arguments, and returns the result of the second expression
    681 <code>any2</code>. See also <code><a href="refN.html#nil">nil</a></code>,
    682 <code><a href="refT.html#t">t</a></code>, <code><a
    683 href="refP.html#prog">prog</a></code> and <code><a
    684 href="refP.html#prog1">prog1</a></code>.
    685 
    686 <pre><code>
    687 : (prog2 (print 1) (print 2) (print 3))
    688 123-> 2
    689 </code></pre>
    690 
    691 <dt><a name="prop"><code>(prop 'sym1|lst ['sym2|cnt ..] 'sym) -> var</code></a>
    692 <dd>Fetches a property for a property key <code>sym</code> from a symbol. That
    693 symbol is <code>sym1</code> (if no other arguments are given), or a symbol found
    694 by applying the <code><a href="refG.html#get">get</a></code> algorithm to
    695 <code>sym1|lst</code> and the following arguments. The property (the cons pair,
    696 not just its value) is returned, suitable for direct (destructive) manipulations
    697 with functions expecting a <code>var</code> argument. See also <code><a
    698 href="ref_.html#::">::</a></code>.
    699 
    700 <pre><code>
    701 : (put 'X 'cnt 0)
    702 -> 0
    703 : (prop 'X 'cnt)
    704 -> (0 . cnt)
    705 : (inc (prop 'X 'cnt))        # Directly manipulate the property value
    706 -> 1
    707 : (get 'X 'cnt)
    708 -> 1
    709 </code></pre>
    710 
    711 <dt><a name="protect"><code>(protect . prg) -> any</code></a>
    712 <dd>Executes <code>prg</code>, and returns the result of the last expression. If
    713 a signal is received during that time, its handling will be delayed until the
    714 execution of <code>prg</code> is completed. See also <code><a
    715 href="refA.html#alarm">alarm</a></code>, <a href="refH.html#*Hup">*Hup</a>, <a
    716 href="refS.html#*Sig1">*Sig[12]</a> and <code><a
    717 href="refK.html#kill">kill</a></code>.
    718 
    719 <pre><code>
    720 : (protect (journal "db1.log" "db2.log"))
    721 -> T
    722 </code></pre>
    723 
    724 <dt><a name="prove"><code>(prove 'lst ['lst]) -> lst</code></a>
    725 <dd>The <a href="ref.html#pilog">Pilog</a> interpreter. Tries to prove the query
    726 list in the first argument, and returns an association list of symbol-value
    727 pairs, or <code>NIL</code> if not successful. The query list is modified as a
    728 side effect, allowing subsequent calls to <code>prove</code> for further
    729 results. The optional second argument may contain a list of symbols; in that
    730 case the successful matches of rules defined for these symbols will be traced.
    731 See also <code><a href="refG.html#goal">goal</a></code>, <code><a
    732 href="ref_.html#->">-&gt</a></code> and <code><a
    733 href="refU.html#unify">unify</a></code>.
    734 
    735 <pre><code>
    736 : (prove (goal '((equal 3 3))))
    737 -> T
    738 : (prove (goal '((equal 3 @X))))
    739 -> ((@X . 3))
    740 : (prove (goal '((equal 3 4))))
    741 -> NIL
    742 </code></pre>
    743 
    744 <dt><a name="prune"><code>(prune ['flg])</code></a>
    745 <dd>Optimizes memory usage by pruning in-memory leaf nodes of database trees.
    746 Typically called repeatedly during heavy data imports. If <code>flg</code> is
    747 non-<code>NIL</code>, further pruning will be disabled. See also <code><a
    748 href="refL.html#lieu">lieu</a></code>.
    749 
    750 <pre><code>
    751 (in File1
    752    (while (someData)
    753       (new T '(+Cls1) ..)
    754       (at (0 . 10000) (commit) (prune)) ) )
    755 (in File2
    756    (while (moreData)
    757       (new T '(+Cls2) ..)
    758       (at (0 . 10000) (commit) (prune)) ) )
    759 (commit)
    760 (prune T)
    761 </code></pre>
    762 
    763 <dt><a name="push"><code>(push 'var 'any ..) -> any</code></a>
    764 <dd>Implements a stack using a list in <code>var</code>. The <code>any</code>
    765 arguments are cons'ed in front of the value list. See also <code><a
    766 href="refP.html#push1">push1</a></code>, <code><a
    767 href="refP.html#pop">pop</a></code>, <code><a
    768 href="refQ.html#queue">queue</a></code> and <code><a
    769 href="refF.html#fifo">fifo</a></code>.
    770 
    771 <pre><code>
    772 : (push 'S 3)              # Use the VAL of 'S' as a stack
    773 -> 3
    774 : S
    775 -> (3)
    776 : (push 'S 2)
    777 -> 2
    778 : (push 'S 1)
    779 -> 1
    780 : S
    781 -> (1 2 3)
    782 : (push S 999)             # Now use the CAR of the list in 'S'
    783 -> 999
    784 : (push S 888 777)
    785 -> 777
    786 : S
    787 -> ((777 888 999 . 1) 2 3)
    788 </code></pre>
    789 
    790 <dt><a name="push1"><code>(push1 'var 'any ..) -> any</code></a>
    791 <dd>Maintains a unique list in <code>var</code>. Each <code>any</code> argument
    792 is cons'ed in front of the value list only if it is not already a <code><a
    793 href="refM.html#member">member</a></code> of that list. See also <code><a
    794 href="refP.html#push">push</a></code>, <code><a
    795 href="refP.html#pop">pop</a></code> and <code><a
    796 href="refQ.html#queue">queue</a></code>.
    797 
    798 <pre><code>
    799 : (push1 'S 1 2 3)
    800 -> 3
    801 : S
    802 -> (3 2 1)
    803 : (push1 'S 2 4)
    804 -> 4
    805 : S
    806 -> (4 3 2 1)
    807 </code></pre>
    808 
    809 <dt><a name="put"><code>(put 'sym1|lst ['sym2|cnt ..] 'sym|0 'any) ->
    810 any</code></a> <dd>Stores a new value <code>any</code> for a property key
    811 <code>sym</code> (or in the symbol value for zero) in a symbol. That symbol is
    812 <code>sym1</code> (if no other arguments are given), or a symbol found by
    813 applying the <code><a href="refG.html#get">get</a></code> algorithm to
    814 <code>sym1|lst</code> and the following arguments. See also <code><a
    815 href="ref_.html#=:">=:</a></code>.
    816 
    817 <pre><code>
    818 : (put 'X 'a 1)
    819 -> 1
    820 : (get 'X 'a)
    821 -> 1
    822 : (prop 'X 'a)
    823 -> (1 . a)
    824 
    825 : (setq L '(A B C))
    826 -> (A B C)
    827 : (setq B 'D)
    828 -> D
    829 : (put L 2 0 'p 5)  # Store '5' under the 'p' propery of the value of 'B'
    830 -> 5
    831 : (getl 'D)
    832 -> ((5 . p))
    833 </code></pre>
    834 
    835 <dt><a name="put!"><code>(put! 'obj 'sym 'any) -> any</code></a>
    836 <dd><a href="ref.html#trans">Transaction</a> wrapper function for <code><a
    837 href="refP.html#put">put</a></code>. Note that for setting property values of
    838 entities typically the <code><a
    839 href="refE.html#entityMesssages">put!></a></code> message is used. See also
    840 <code><a href="refN.html#new!">new!</a></code>, <code><a
    841 href="refS.html#set!">set!</a></code> and <code><a
    842 href="refI.html#inc!">inc!</a></code>.
    843 
    844 <pre><code>
    845 (put! Obj 'cnt 0)  # Setting a property of a non-entity object
    846 </code></pre>
    847 
    848 <dt><a name="putl"><code>(putl 'sym1|lst1 ['sym2|cnt ..] 'lst) -> lst</code></a>
    849 <dd>Stores a complete new property list <code>lst</code> in a symbol. That
    850 symbol is <code>sym1</code> (if no other arguments are given), or a symbol found
    851 by applying the <code><a href="refG.html#get">get</a></code> algorithm to
    852 <code>sym1|lst1</code> and the following arguments. All previously defined
    853 properties for that symbol are lost. See also <code><a
    854 href="refG.html#getl">getl</a></code> and <code><a
    855 href="refM.html#maps">maps</a></code>.
    856 
    857 <pre><code>
    858 : (putl 'X '((123 . a) flg ("Hello" . b)))
    859 -> ((123 . a) flg ("Hello" . b))
    860 : (get 'X 'a)
    861 -> 123
    862 : (get 'X 'b)
    863 -> "Hello"
    864 : (get 'X 'flg)
    865 -> T
    866 </code></pre>
    867 
    868 <dt><a name="pwd"><code>(pwd) -> sym</code></a>
    869 <dd>Returns the path to the current working directory. See also <code><a
    870 href="refD.html#dir">dir</a></code> and <code><a
    871 href="refC.html#cd">cd</a></code>.
    872 
    873 <pre><code>
    874 : (pwd)
    875 -> "/home/app/"
    876 </code></pre>
    877 
    878 </dl>
    879 
    880 </body>
    881 </html>