picolisp

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

refS.html (34799B)


      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>S</title>
      6 <link rel="stylesheet" href="doc.css" type="text/css">
      7 </head>
      8 <body>
      9 
     10 <h1>S</h1>
     11 
     12 <dl>
     13 
     14 <dt><a name="*Scl"><code>*Scl</code></a>
     15 <dd>A global variable holding the current fixpoint input scale. See also <a
     16 href="ref.html#num-io">Numbers</a> and <code><a
     17 href="refS.html#scl">scl</a></code>.
     18 
     19 <pre><code>
     20 : (str "123.45")  # Default value of '*Scl' is 0
     21 -> (123)
     22 : (setq *Scl 3)
     23 -> 3
     24 : (str "123.45")
     25 -> (123450)
     26 
     27 : 123.4567
     28 -> 123457
     29 : 12.3456
     30 -> 12346
     31 </code></pre>
     32 
     33 <dt><a name="*Sig1"><code>*Sig1</code></a>
     34 <dt><a name="*Sig2"><code>*Sig2</code></a>
     35 <dd>Global variables holding (possibly empty) <code>prg</code> bodies, which
     36 will be executed when a SIGUSR1 signal (or a SIGUSR2 signal, respectively) is
     37 sent to the current process. See also <code><a
     38 href="refA.html#alarm">alarm</a></code>, <code><a
     39 href="refS.html#sigio">sigio</a></code> and <code><a
     40 href="refH.html#*Hup">*Hup</a></code>.
     41 
     42 <pre><code>
     43 : (de *Sig1 (msg 'SIGUSR1))
     44 -> *Sig1
     45 </code></pre>
     46 
     47 <dt><a name="*Solo"><code>*Solo</code></a>
     48 <dd>A global variable indicating exclusive database access. Its value is
     49 <code>0</code> initially, set to <code>T</code> (or <code>NIL</code>) during
     50 cooperative database locks when <code><a href="refL.html#lock">lock</a></code>
     51 is successfully called with a <code>NIL</code> (or non-<code>NIL</code>)
     52 argument. See also <code><a href="refZ.html#*Zap">*Zap</a></code>.
     53 
     54 <pre><code>
     55 : *Solo
     56 -> 0
     57 : (lock *DB)
     58 -> NIL
     59 : *Solo
     60 -> NIL
     61 : (rollback)
     62 -> T
     63 : *Solo
     64 -> 0
     65 : (lock)
     66 -> NIL
     67 : *Solo
     68 -> T
     69 : (rollback)
     70 -> T
     71 : *Solo
     72 -> T
     73 </code></pre>
     74 
     75 <dt><a name="+Sn"><code>+Sn</code></a>
     76 <dd>Prefix class for maintaining indexes according to a modified soundex
     77 algorithm, for tolerant name searches, to <code><a
     78 href="refS.html#+String">+String</a></code> relations. Typically used in
     79 combination with the <code><a href="refI.html#+Idx">+Idx</a></code> prefix
     80 class. See also <a href="ref.html#dbase">Database</a>.
     81 
     82 <pre><code>
     83 (rel nm (+Sn +Idx +String))  # Name
     84 </code></pre>
     85 
     86 <dt><a name="+String"><code>+String</code></a>
     87 <dd>Class for string (transient symbol) relations, a subclass of <code><a
     88 href="refS.html#+Symbol">+Symbol</a></code>. Accepts an optional argument for
     89 the string length (currently not used). See also <a
     90 href="ref.html#dbase">Database</a>.
     91 
     92 <pre><code>
     93 (rel nm (+Sn +Idx +String))  # Name, indexed by soundex and substrings
     94 </code></pre>
     95 
     96 <dt><a name="+Swap"><code>+Swap</code></a>
     97 <dd>Prefix class for <code><a href="refR.html#+relation">+relation</a></code>s
     98 where the data are to be stored in the value of a separate external symbol
     99 instead of the relation's object. Typically used for data which are relatively
    100 large and/or rarely accessed. Doesn't work with bidirectional relations
    101 (<code><a href="refJ.html#+Joint">+Joint</a></code> or <code><a
    102 href="refI.html#+index">+index</a></code>). See also <a
    103 href="ref.html#dbase">Database</a>.
    104 
    105 <pre><code>
    106 (rel pw (+Swap +String))               # Password
    107 (rel nr (+Swap +List +Number))         # List of bignums
    108 </code></pre>
    109 
    110 <dt><a name="+Symbol"><code>+Symbol</code></a>
    111 <dd>Class for symbolic relations, a subclass of <code><a
    112 href="refR.html#+relation">+relation</a></code>. Objects of that class typically
    113 maintain internal symbols, as opposed to the more often-used <code><a
    114 href="refS.html#+String">+String</a></code> for transient symbols. See also <a
    115 href="ref.html#dbase">Database</a>.
    116 
    117 <pre><code>
    118 (rel perm (+List +Symbol))  # Permission list
    119 </code></pre>
    120 
    121 <dt><a name="same/3"><code>same/3</code></a>
    122 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the first
    123 argument matches the result of applying the <code><a
    124 href="refG.html#get">get</a></code> algorithm to the following arguments.
    125 Typically used as filter predicate in <code><a
    126 href="refS.html#select/3">select/3</a></code> database queries. See also
    127 <code><a href="refI.html#isa/2">isa/2</a></code>, <code><a
    128 href="refB.html#bool/3">bool/3</a></code>, <code><a
    129 href="refR.html#range/3">range/3</a></code>, <code><a
    130 href="refH.html#head/3">head/3</a></code>, <code><a
    131 href="refF.html#fold/3">fold/3</a></code>, <code><a
    132 href="refP.html#part/3">part/3</a></code> and <code><a
    133 href="refT.html#tolr/3">tolr/3</a></code>.
    134 
    135 <pre><code>
    136 : (?
    137    @Nr 2
    138    @Nm "Spare"
    139    (select (@Item)
    140       ((nr +Item @Nr) (nm +Item @Nm))
    141       (same @Nr @Item nr)
    142       (head @Nm @Item nm) ) )
    143  @Nr=2 @Nm="Spare" @Item={3-2}
    144 </code></pre>
    145 
    146 <dt><a name="scan"><code>(scan 'tree ['fun] ['any1] ['any2] ['flg])</code></a>
    147 <dd>Scans through a database tree by applying <code>fun</code> to all key-value
    148 pairs. <code>fun</code> should be a function accepting two arguments for key and
    149 value. It defaults to <code><a href="refP.html#println">println</a></code>.
    150 <code>any1</code> and <code>any2</code> may specify a range of keys. If
    151 <code>any2</code> is greater than <code>any1</code>, the traversal will be in
    152 opposite direction. Note that the keys need not to be atomic, depending on the
    153 application's index structure. If <code>flg</code> is non-<code>NIL</code>,
    154 partial keys are skipped. See also <code><a
    155 href="refT.html#tree">tree</a></code>, <code><a
    156 href="refI.html#iter">iter</a></code>, <code><a
    157 href="refI.html#init">init</a></code> and <code><a
    158 href="refS.html#step">step</a></code>.
    159 
    160 <pre><code>
    161 : (scan (tree 'nm '+Item))
    162 ("ASLRSNSTRSTN" {3-3} . T) {3-3}
    163 ("Additive" {3-4}) {3-4}
    164 ("Appliance" {3-6}) {3-6}
    165 ("Auxiliary Construction" . {3-3}) {3-3}
    166 ("Construction" {3-3}) {3-3}
    167 ("ENNSNNTTTF" {3-4} . T) {3-4}
    168 ("Enhancement Additive" . {3-4}) {3-4}
    169 ("Fittings" {3-5}) {3-5}
    170 ("GTSTFLNS" {3-6} . T) {3-6}
    171 ("Gadget Appliance" . {3-6}) {3-6}
    172 ...
    173 
    174 : (scan (tree 'nm '+Item) println NIL T T)  # 'flg' is non-NIL
    175 ("Auxiliary Construction" . {3-3}) {3-3}
    176 ("Enhancement Additive" . {3-4}) {3-4}
    177 ("Gadget Appliance" . {3-6}) {3-6}
    178 ("Main Part" . {3-1}) {3-1}
    179 ("Metal Fittings" . {3-5}) {3-5}
    180 ("Spare Part" . {3-2}) {3-2}
    181 ("Testartikel" . {3-8}) {3-8}
    182 -> {7-6}
    183 </code></pre>
    184 
    185 <dt><a name="scl"><code>(scl 'num [. prg]) -> num</code></a>
    186 <dd>If <code>prg</code> is given, it binds <code><a
    187 href="refS.html#*Scl">*Scl</a></code> dynamically to <code>num</code> during the
    188 execution of <code>prg</code>. Otherwise, it sets <code><a
    189 href="refS.html#*Scl">*Scl</a></code> globally to <code>num</code>. See also <a
    190 href="ref.html#num-io">Numbers</a>.
    191 
    192 <pre><code>
    193 : (scl 0)
    194 -> 0
    195 : (str "123.45")
    196 -> (123)
    197 : (scl 1)
    198 -> 1
    199 : (read)
    200 123.45
    201 -> 1235
    202 : (scl 3)
    203 -> 3
    204 : (str "123.45")
    205 -> (123450)
    206 : (scl 1 (str "123.45"))
    207 -> (1235)
    208 : *Scl
    209 -> 3
    210 </code></pre>
    211 
    212 <dt><a name="script"><code>(script 'any ..) -> any</code></a>
    213 <dd>The first <code>any</code> argument is <code><a
    214 href="refL.html#load">load</a></code>ed, with the remaining arguments <code><a
    215 href="refP.html#pass">pass</a></code>ed as variable arguments. They can be
    216 accessed with <code><a href="refN.html#next">next</a></code>, <code><a
    217 href="refA.html#arg">arg</a></code>, <code><a
    218 href="refA.html#args">args</a></code> and <code><a
    219 href="refR.html#rest">rest</a></code>. With that, the syntax in the script is
    220 the same as that in the body of a function with variable arguments (see <a
    221 href="ref.html#lambda">lambda expression</a>s, "when the CAR is the symbol @").
    222 
    223 <pre><code>
    224 $ cat x
    225 (* (next) (next))
    226 
    227 $ pil +
    228 : (script "x" 3 4)
    229 -> 12
    230 </code></pre>
    231 
    232 <dt><a name="sect"><code>(sect 'lst 'lst) -> lst</code></a>
    233 <dd>Returns the intersection of the <code>lst</code> arguments. See also
    234 <code><a href="refD.html#diff">diff</a></code>.
    235 
    236 <pre><code>
    237 : (sect (1 2 3 4) (3 4 5 6))
    238 -> (3 4)
    239 : (sect (1 2 3) (4 5 6))
    240 -> NIL
    241 </code></pre>
    242 
    243 <dt><a name="seed"><code>(seed 'any) -> cnt</code></a>
    244 <dd>Initializes the random generator's seed, and returns a pseudo random number
    245 in the range -2147483648 .. +2147483647. See also <code><a
    246 href="refR.html#rand">rand</a></code> and <code><a
    247 href="refH.html#hash">hash</a></code>.
    248 
    249 <pre><code>
    250 : (seed "init string")
    251 -> 2015582081
    252 : (rand)
    253 -> -706917003
    254 : (rand)
    255 -> 1224196082
    256 
    257 : (seed (time))
    258 -> 128285383
    259 </code></pre>
    260 
    261 <dt><a name="seek"><code>(seek 'fun 'lst ..) -> lst</code></a>
    262 <dd>Applies <code>fun</code> to <code>lst</code> and all successive CDRs, until
    263 non-<code>NIL</code> is returned. Returns the tail of <code>lst</code> starting
    264 with that element, or <code>NIL</code> if <code>fun</code> did not return
    265 non-<code>NIL</code> for any element of <code>lst</code>. When additional
    266 <code>lst</code> arguments are given, they are passed to <code>fun</code> in the
    267 same way. See also <code><a href="refF.html#find">find</a></code>, <code><a
    268 href="refP.html#pick">pick</a></code>.
    269 
    270 <pre><code>
    271 : (seek '((X) (> (car X) 9)) (1 5 8 12 19 22))
    272 -> (12 19 22)
    273 </code></pre>
    274 
    275 <dt><a name="select"><code>(select [var ..] cls [hook|T] [var val ..]) -> obj | NIL</code></a>
    276 <dd>(Debug mode only) Interactive database function, loosely modelled after the
    277 SQL '<code>SELECT</code>' command. A (limited) front-end to the Pilog <code><a
    278 href="refS.html#select/3">select/3</a></code> predicate. When called with only a
    279 <code>cls</code> argument, <code>select</code> steps through all objects of that
    280 class, and <code><a href="refS.html#show">show</a></code>s their complete
    281 contents (this is analog to 'SELECT * from CLS'). If <code>cls</code> is
    282 followed by attribute/value specifications, the search is limited to these
    283 values (this is analog to 'SELECT * from CLS where VAR = VAL'). If between the
    284 <code>select</code> function and <code>cls</code> one or several attribute names
    285 are supplied, only these attribute (instead of the full <code>show</code>) are
    286 printed. These attribute specifications may also be lists, then the <code><a
    287 href="refG.html#get">get</a></code> algorithm will be used to retrieve related
    288 data. See also <code><a href="refU.html#update">update</a></code>, <a
    289 href="ref.html#dbase">Database</a> and <a href="ref.html#pilog">Pilog</a>.
    290 
    291 <pre><code>
    292 : (select +Item)                       # Show all items
    293 {3-1} (+Item)
    294    nr 1
    295    pr 29900
    296    inv 100
    297    sup {2-1}
    298    nm "Main Part"
    299 
    300 {3-2} (+Item)
    301    nr 2
    302    pr 1250
    303    inv 100
    304    sup {2-2}
    305    nm "Spare Part"
    306 .                                      # Stop
    307 -> {3-2}
    308 
    309 : (select +Item nr 3)                  # Show only item 3
    310 {3-3} (+Item)
    311    nr 3
    312    sup {2-1}
    313    pr 15700
    314    nm "Auxiliary Construction"
    315    inv 100
    316 .                                      # Stop
    317 -> {3-3}
    318 
    319 # Show selected attributes for items 3 through 3
    320 : (select nr nm pr (sup nm) +Item nr (3 . 5))
    321 3 "Auxiliary Construction" 157.00 "Active Parts Inc." {3-3}
    322 4 "Enhancement Additive" 9.99 "Seven Oaks Ltd." {3-4}
    323 5 "Metal Fittings" 79.80 "Active Parts Inc." {3-5}
    324 -> NIL
    325 </code></pre>
    326 
    327 <dt><a name="select/3"><code>select/3</code></a>
    328 <dd><a href="ref.html#pilog">Pilog</a> database predicate that allows combined
    329 searches over <code><a href="refI.html#+index">+index</a></code> and other
    330 relations. It takes a list of Pilog variables, a list of generator clauses, and
    331 an arbitrary number of filter clauses. The functionality is described in detail
    332 in <a href="select.html">The 'select' Predicate</a>. See also <code><a
    333 href="refD.html#db/3">db/3</a></code>, <code><a
    334 href="refI.html#isa/2">isa/2</a></code>, <code><a
    335 href="refS.html#same/3">same/3</a></code>, <code><a
    336 href="refB.html#bool/3">bool/3</a></code>, <code><a
    337 href="refR.html#range/3">range/3</a></code>, <code><a
    338 href="refH.html#head/3">head/3</a></code>, <code><a
    339 href="refF.html#fold/3">fold/3</a></code>, <code><a
    340 href="refP.html#part/3">part/3</a></code>, <code><a
    341 href="refT.html#tolr/3">tolr/3</a></code> and <code><a
    342 href="refR.html#remote/2">remote/2</a></code>.
    343 
    344 <pre><code>
    345 : (?
    346    @Nr (2 . 5)          # Select all items with numbers between 2 and 5
    347    @Sup "Active"        # and suppliers matching "Active"
    348    (select (@Item)                                  # Bind results to '@Item'
    349       ((nr +Item @Nr) (nm +CuSu @Sup (sup +Item)))  # Generator clauses
    350       (range @Nr @Item nr)                          # Filter clauses
    351       (part @Sup @Item sup nm) ) )
    352  @Nr=(2 . 5) @Sup="Active" @Item={3-3}
    353  @Nr=(2 . 5) @Sup="Active" @Item={3-5}
    354 -> NIL
    355 </code></pre>
    356 
    357 <dt><a name="send"><code>(send 'msg 'obj ['any ..]) -> any</code></a>
    358 <dd>Sends the message <code>msg</code> to the object <code>obj</code>,
    359 optionally with arguments <code>any</code>. If the message cannot be located in
    360 <code>obj</code>, its classes and superclasses, an error <code>"Bad
    361 message"</code> is issued. See also <a href="ref.html#oop">OO Concepts</a>,
    362 <code><a href="refT.html#try">try</a></code>, <code><a
    363 href="refM.html#method">method</a></code>, <code><a
    364 href="refM.html#meth">meth</a></code>, <code><a
    365 href="refS.html#super">super</a></code> and <code><a
    366 href="refE.html#extra">extra</a></code>.
    367 
    368 <pre><code>
    369 : (send 'stop> Dlg)  # Equivalent to (stop> Dlg)
    370 -> NIL
    371 </code></pre>
    372 
    373 <dt><a name="seq"><code>(seq 'cnt|sym1) -> sym | NIL</code></a>
    374 <dd>Sequential single step: Returns the <i>first</i> external symbol in the
    375 <code>cnt</code>'th database file, or the <i>next</i> external symbol following
    376 <code>sym1</code> in the database, or <code>NIL</code> when the end of the
    377 database is reached. See also <code><a href="refF.html#free">free</a></code>.
    378 
    379 <pre><code>
    380 : (pool "db")
    381 -> T
    382 : (seq *DB)
    383 -> {2}
    384 : (seq @)
    385 -> {3}
    386 </code></pre>
    387 
    388 <dt><a name="set"><code>(set 'var 'any ..) -> any</code></a>
    389 <dd>Stores new values <code>any</code> in the <code>var</code> arguments. See
    390 also <code><a href="refS.html#setq">setq</a></code>, <code><a
    391 href="refV.html#val">val</a></code>, <code><a
    392 href="refC.html#con">con</a></code> and <code><a
    393 href="refD.html#def">def</a></code>.
    394 
    395 <pre><code>
    396 : (set 'L '(a b c)  (cdr L) '999)
    397 -> 999
    398 : L
    399 -> (a 999 c)
    400 </code></pre>
    401 
    402 <dt><a name="set!"><code>(set! 'obj 'any) -> any</code></a>
    403 <dd><a href="ref.html#trans">Transaction</a> wrapper function for <code><a
    404 href="refS.html#set">set</a></code>. Note that for setting the value of entities
    405 typically the <code><a href="refE.html#entityMesssages">set!></a></code> message
    406 is used. See also <code><a href="refN.html#new!">new!</a></code>, <code><a
    407 href="refP.html#put!">put!</a></code> and <code><a
    408 href="refI.html#inc!">inc!</a></code>.
    409 
    410 <pre><code>
    411 (set! Obj (* Count Size))  # Setting a non-entity object to a numeric value
    412 </code></pre>
    413 
    414 <dt><a name="setq"><code>(setq var 'any ..) -> any</code></a>
    415 <dd>Stores new values <code>any</code> in the <code>var</code> arguments. See
    416 also <code><a href="refS.html#set">set</a></code>, <code><a
    417 href="refV.html#val">val</a></code> and <code><a
    418 href="refD.html#def">def</a></code>.
    419 
    420 <pre><code>
    421 : (setq  A 123  B (list A A))  # Set 'A' to 123, then 'B' to (123 123)
    422 -> (123 123)
    423 </code></pre>
    424 
    425 <dt><a name="show"><code>(show 'any ['sym|cnt ..]) -> any</code></a>
    426 <dd>Shows the name, value and property list of a symbol found by applying the
    427 <code><a href="refG.html#get">get</a></code> algorithm to <code>any</code> and
    428 the following arguments. See also <code><a href="refE.html#edit">edit</a></code>
    429 and <code><a href="refV.html#view">view</a></code>.
    430 
    431 <pre><code>
    432 : (setq A 123456)
    433 -> 123456
    434 : (put 'A 'x 1)
    435 -> 1
    436 : (put 'A 'lst (9 8 7))
    437 -> (9 8 7)
    438 : (put 'A 'flg T)
    439 -> T
    440 
    441 : (show 'A)
    442 A 123456
    443    flg
    444    lst (9 8 7)
    445    x 1
    446 -> A
    447 
    448 : (show 'A 'lst 2)
    449 -> 8
    450 </code></pre>
    451 
    452 <dt><a name="show/1"><code>show/1</code></a>
    453 <dd><a href="ref.html#pilog">Pilog</a> predicate that always succeeds, and shows
    454 the name, value and property list of the argument symbol. See also <code><a
    455 href="refS.html#show">show</a></code>.
    456 
    457 <pre><code>
    458 : (? (db nr +Item 2 @Item) (show @Item))
    459 {3-2} (+Item)
    460    nm "Spare Part"
    461    nr 2
    462    pr 1250
    463    inv 100
    464    sup {2-2}
    465  @Item={3-2}
    466 -> NIL
    467 </code></pre>
    468 
    469 <dt><a name="sigio"><code>(sigio 'cnt . prg) -> cnt</code></a>
    470 <dd>Sets a signal handler <code>prg</code> for SIGIO on the file descriptor
    471 <code>cnt</code>. Returns the file descriptor. See also <code><a
    472 href="refA.html#alarm">alarm</a></code>, <code><a
    473 href="refH.html#*Hup">*Hup</a></code> and <code><a
    474 href="refS.html#*Sig1">*Sig[12]</a></code>.
    475 
    476 <pre><code>
    477 # First session
    478 : (sigio (setq *SigSock (port T 4444))  # Register signal handler at UDP port
    479    (while (udp *SigSock)                # Queue all received data
    480       (fifo '*SigQueue @) ) )
    481 -> 3
    482 
    483 # Second session
    484 : (for I 7 (udp "localhost" 4444 I))  # Send numbers to first session
    485 
    486 # First session
    487 : (fifo '*SigQueue)
    488 -> 1
    489 : (fifo '*SigQueue)
    490 -> 2
    491 </code></pre>
    492 
    493 <dt><a name="size"><code>(size 'any) -> cnt</code></a>
    494 <dd>Returns the "size" of <code>any</code>. For numbers this is the number of
    495 bytes needed for the value, for external symbols it is the number of bytes it
    496 would occupy in the database, for other symbols it is the number of bytes
    497 occupied by the UTF-8 representation of the name, and for lists it is the total
    498 number of cells in this list and all its sublists. See also <code><a
    499 href="refL.html#length">length</a></code> and <code><a
    500 href="refB.html#bytes">bytes</a></code>.
    501 
    502 <pre><code>
    503 : (size "abc")
    504 -> 3
    505 : (size "äbc")
    506 -> 4
    507 : (size 127)  # One byte
    508 -> 1
    509 : (size 128)  # Two bytes (eight bits plus sign bit!)
    510 -> 2
    511 : (size (1 (2) 3))
    512 -> 4
    513 : (size (1 2 3 .))
    514 -> 3
    515 </code></pre>
    516 
    517 <dt><a name="skip"><code>(skip ['any]) -> sym</code></a>
    518 <dd>Skips all whitespace (and comments if <code>any</code> is given) in the
    519 input stream. Returns the next available character, or <code>NIL</code> upon end
    520 of file. See also <code><a href="refP.html#peek">peek</a></code> and <code><a
    521 href="refE.html#eof">eof</a></code>.
    522 
    523 <pre><code>
    524 $ cat a
    525 # Comment
    526 abcd
    527 $ pil +
    528 : (in "a" (skip "#"))
    529 -> "a"
    530 </code></pre>
    531 
    532 <dt><a name="solve"><code>(solve 'lst [. prg]) -> lst</code></a>
    533 <dd>Evaluates a <a href="ref.html#pilog">Pilog</a> query and, returns the list
    534 of result sets. If <code>prg</code> is given, it is executed for each result
    535 set, with all Pilog variables bound to their matching values, and returns a list
    536 of the results. See also <code><a href="refP.html#pilog">pilog</a></code>,
    537 <code><a href="ref_.html#?">?</a></code>, <code><a
    538 href="refG.html#goal">goal</a></code> and <code><a
    539 href="refP.html#prove">prove</a></code>.
    540 
    541 <pre><code>
    542 : (solve '((append @X @Y (a b c))))
    543 -> (((@X) (@Y a b c)) ((@X a) (@Y b c)) ((@X a b) (@Y c)) ((@X a b c) (@Y)))
    544 
    545 : (solve '((append @X @Y (a b c))) @X)
    546 -> (NIL (a) (a b) (a b c))
    547 </code></pre>
    548 
    549 <dt><a name="sort"><code>(sort 'lst ['fun]) -> lst</code></a>
    550 <dd>Sorts <code>lst</code> by destructively exchanging its elements. If
    551 <code>fun</code> is given, it is used as a "less than" predicate for
    552 comparisons. Typically, <code>sort</code> is used in combination with <a
    553 href="refB.html#by">by</a>, giving shorter and often more efficient solutions
    554 than with the predicate function. See also <a href="ref.html#cmp">Comparing</a>,
    555 <code><a href="refG.html#group">group</a></code>, <code><a
    556 href="refM.html#maxi">maxi</a></code>, <code><a
    557 href="refM.html#mini">mini</a></code> and <code><a
    558 href="refU.html#uniq">uniq</a></code>.
    559 
    560 <pre><code>
    561 : (sort '(a 3 1 (1 2 3) d b 4 T NIL (a b c) (x y z) c 2))
    562 -> (NIL 1 2 3 4 a b c d (1 2 3) (a b c) (x y z) T)
    563 : (sort '(a 3 1 (1 2 3) d b 4 T NIL (a b c) (x y z) c 2) >)
    564 -> (T (x y z) (a b c) (1 2 3) d c b a 4 3 2 1 NIL)
    565 : (by cadr sort '((1 4 3) (5 1 3) (1 2 4) (3 8 5) (6 4 5)))
    566 -> ((5 1 3) (1 2 4) (1 4 3) (6 4 5) (3 8 5))
    567 </code></pre>
    568 
    569 <dt><a name="space"><code>(space ['cnt]) -> cnt</code></a>
    570 <dd>Prints <code>cnt</code> spaces, or a single space when <code>cnt</code> is
    571 not given.
    572 
    573 <pre><code>
    574 : (space)
    575  -> 1
    576 : (space 1)
    577  -> 1
    578 : (space 2)
    579   -> 2
    580 </code></pre>
    581 
    582 <dt><a name="sp?"><code>(sp? 'any) -> flg</code></a>
    583 <dd>Returns <code>T</code> when the argument <code>any</code> is
    584 <code>NIL</code>, or if it is a string (symbol) that consists only of whitespace
    585 characters.
    586 
    587 <pre><code>
    588 : (sp? "  ")
    589 -> T
    590 : (sp? "ABC")
    591 -> NIL
    592 : (sp? 123)
    593 -> NIL
    594 </code></pre>
    595 
    596 <dt><a name="split"><code>(split 'lst 'any ..) -> lst</code></a>
    597 <dd>Splits <code>lst</code> at all places containing an element <code>any</code>
    598 and returns the resulting list of sublists. See also <code><a
    599 href="refS.html#stem">stem</a></code>.
    600 
    601 <pre><code>
    602 : (split (1 a 2 b 3 c 4 d 5 e 6) 'e 3 'a)
    603 -> ((1) (2 b) (c 4 d 5) (6))
    604 : (mapcar pack (split (chop "The quick brown fox") " "))
    605 -> ("The" "quick" "brown" "fox")
    606 </code></pre>
    607 
    608 <dt><a name="sqrt"><code>(sqrt 'num ['flg]) -> num</code></a>
    609 <dd>Returns the square root of the <code>num</code> argument. If
    610 <code>flg</code> is given and non-<code>NIL</code>, the result will be rounded.
    611 
    612 <pre><code>
    613 : (sqrt 64)
    614 -> 8
    615 : (sqrt 1000)
    616 -> 31
    617 : (sqrt 1000 T)
    618 -> 32
    619 : (sqrt 10000000000000000000000000000000000000000)
    620 -> 100000000000000000000
    621 </code></pre>
    622 
    623 <dt><a name="stack"><code>(stack ['cnt]) -> cnt | (.. sym . cnt)</code></a>
    624 <dd>(64-bit version only) Maintains the stack segment size for <a
    625 href="ref.html#coroutines">coroutines</a> (the main stack segment is limited -
    626 while at least one coroutine is running - to four times that size). If called
    627 without a <code>cnt</code> argument, or if already one or more coroutines are
    628 running, the current size in megabytes is returned. Otherwise, the stack segment
    629 size is set to the new value (default 1 MB). The main segment's size is always
    630 four times the size of coroutine segments. If there are running coroutines,
    631 their tags will be <code><a href="refC.html#cons">cons</a></code>ed in front of
    632 the size. See also <code><a href="refH.html#heap">heap</a></code>.
    633 
    634 <pre><code>
    635 $ ulimit -s unlimited  &&  pil +  # Guarantee stack space
    636 : (stack)      # Current size
    637 -> 1
    638 : (stack 4)    # Set to 4 MB
    639 -> 4
    640 : (co 'inc (let N 0 (loop (yield (inc 'N)))))  # Create two coroutines
    641 -> 1
    642 : (co 'dec (let N 0 (loop (yield (dec 'N)))))
    643 -> -1
    644 : (stack)
    645 -> (dec inc . 4)
    646 </code></pre>
    647 
    648 <dt><a name="stamp"><code>(stamp ['dat 'tim]|['T]) -> sym</code></a>
    649 <dd>Returns a date-time string in the form "YYYY-MM-DD HH:MM:SS". If
    650 <code>dat</code> and <code>tim</code> is missing, the current date and time is
    651 used. If <code>T</code> is passed, the current Coordinated Universal Time (UTC)
    652 is used instead. See also <code><a href="refD.html#date">date</a></code> and
    653 <code><a href="refT.html#time">time</a></code>.
    654 
    655 <pre><code>
    656 : (stamp)
    657 -> "2000-09-12 07:48:04"
    658 : (stamp (date) 0)
    659 -> "2000-09-12 00:00:00"
    660 : (stamp (date 2000 1 1) (time 12 0 0))
    661 -> "2000-01-01 12:00:00"
    662 </code></pre>
    663 
    664 <dt><a name="state"><code>(state 'var (sym|lst exe [. prg]) ..) -> any</code></a>
    665 <dd>Implements a finite state machine. The variable <code>var</code> holds the
    666 current state as a symbolic value. When a clause is found that contains the
    667 current state in its CAR <code>sym|lst</code> value, and where the
    668 <code>exe</code> in its CADR evaluates to non-<code>NIL</code>, the current
    669 state will be set to that value, the body <code>prg</code> in the CDDR will be
    670 executed, and the result returned. <code>T</code> is a catch-all for any state.
    671 If no state-condition matches, <code>NIL</code> is returned. See also <code><a
    672 href="refC.html#case">case</a></code>, <code><a
    673 href="refC.html#cond">cond</a></code> and <code><a
    674 href="refJ.html#job">job</a></code>.
    675 
    676 <pre><code>
    677 : (de tst ()
    678    (job '((Cnt . 4))
    679       (state '(start)
    680          (start 'run
    681             (printsp 'start) )
    682          (run (and (gt0 (dec 'Cnt)) 'run)
    683             (printsp 'run) )
    684          (run 'stop
    685             (printsp 'run) )
    686          (stop 'start
    687             (setq Cnt 4)
    688             (println 'stop) ) ) ) )
    689 -> tst
    690 : (do 12 (tst))
    691 start run run run run stop
    692 start run run run run stop
    693 -> stop
    694 : (pp 'tst)
    695 (de tst NIL
    696    (job '((Cnt . 4))
    697       (state '(start)
    698       ...
    699 -> tst
    700 : (do 3 (tst))
    701 start run run -> run
    702 : (pp 'tst)
    703 (de tst NIL
    704    (job '((Cnt . 2))
    705       (state '(run)
    706       ...
    707 -> tst
    708 </code></pre>
    709 
    710 <dt><a name="stem"><code>(stem 'lst 'any ..) -> lst</code></a>
    711 <dd>Returns the tail of <code>lst</code> that does not contain any of the
    712 <code>any</code> arguments. <code>(stem 'lst 'any ..)</code> is equivalent to
    713 <code>(last (split 'lst 'any ..))</code>. See also <code><a
    714 href="refT.html#tail">tail</a></code> and <code><a
    715 href="refS.html#split">split</a></code>.
    716 
    717 <pre><code>
    718 : (stem (chop "abc/def\\ghi") "/" "\\")
    719 -> ("g" "h" "i")
    720 </code></pre>
    721 
    722 <dt><a name="step"><code>(step 'lst ['flg]) -> any</code></a>
    723 <dd>Single-steps iteratively through a database tree. <code>lst</code> is a
    724 structure as received from <code><a href="refI.html#init">init</a></code>. If
    725 <code>flg</code> is non-<code>NIL</code>, partial keys are skipped. See also
    726 <code><a href="refT.html#tree">tree</a></code>, <code><a
    727 href="refS.html#scan">scan</a></code>, <code><a
    728 href="refI.html#iter">iter</a></code>, <code><a
    729 href="refL.html#leaf">leaf</a></code> and <code><a
    730 href="refF.html#fetch">fetch</a></code>.
    731 
    732 <pre><code>
    733 : (setq Q (init (tree 'nr '+Item) 3 5))
    734 -> (((3 . 5) ((3 NIL . {3-3}) (4 NIL . {3-4}) (5 NIL . {3-5}) (6 NIL . {3-6}) (7 NIL . {3-8}))))
    735 : (get (step Q) 'nr)
    736 -> 3
    737 : (get (step Q) 'nr)
    738 -> 4
    739 : (get (step Q) 'nr)
    740 -> 5
    741 : (get (step Q) 'nr)
    742 -> NIL
    743 </code></pre>
    744 
    745 <dt><a name="store"><code>(store 'tree 'any1 'any2 ['(num1 . num2)])</code></a>
    746 <dd>Stores a value <code>any2</code> for the key <code>any1</code> in a database
    747 tree. <code>num1</code> is a database file number, as used in <code><a
    748 href="refN.html#new">new</a></code> (defaulting to 1), and <code>num2</code> a
    749 database block size (defaulting to 256). When <code>any2</code> is
    750 <code>NIL</code>, the corresponding entry is deleted from the tree. See also
    751 <code><a href="refT.html#tree">tree</a></code> and <code><a
    752 href="refF.html#fetch">fetch</a></code>.
    753 
    754 <pre><code>
    755 : (store (tree 'nr '+Item) 2 '{3-2})
    756 </code></pre>
    757 
    758 <dt><a name="str"><code>(str 'sym ['sym1]) -> lst</code></a>
    759 <dt><code>(str 'lst) -> sym</code>
    760 <dd>In the first form, the string <code>sym</code> is parsed into a list. This
    761 mechanism is also used by <code><a href="refL.html#load">load</a></code>. If
    762 <code>sym1</code> is given, it should specify a set of characters, and
    763 <code>str</code> will then return a list of tokens analog to <code><a
    764 href="refR.html#read">read</a></code>. The second form does the reverse
    765 operation by building a string from a list. See also <code><a
    766 href="refA.html#any">any</a></code>, <code><a
    767 href="refN.html#name">name</a></code> and <code><a
    768 href="refS.html#sym">sym</a></code>.
    769 
    770 <pre><code>
    771 : (str "a (1 2) b")
    772 -> (a (1 2) b)
    773 : (str '(a "Hello" DEF))
    774 -> "a \"Hello\" DEF"
    775 : (str "a*3+b*4" "_")
    776 -> (a "*" 3 "+" b "*" 4)
    777 </code></pre>
    778 
    779 <dt><a name="str?"><code>(str? 'any) -> sym | NIL</code></a>
    780 <dd>Returns the argument <code>any</code> when it is a transient symbol
    781 (string), otherwise <code>NIL</code>. See also <code><a
    782 href="refS.html#sym?">sym?</a></code>, <code><a
    783 href="refB.html#box?">box?</a></code> and <code><a
    784 href="refE.html#ext?">ext?</a></code>.
    785 
    786 <pre><code>
    787 : (str? 123)
    788 -> NIL
    789 : (str? '{ABC})
    790 -> NIL
    791 : (str? 'abc)
    792 -> NIL
    793 : (str? "abc")
    794 -> "abc"
    795 </code></pre>
    796 
    797 <dt><a name="strDat"><code>(strDat 'sym) -> dat</code></a>
    798 <dd>Converts a string <code>sym</code> in the date format of the current
    799 <code><a href="refL.html#locale">locale</a></code> to a <code><a
    800 href="refD.html#date">date</a></code>. See also <code><a
    801 href="refE.html#expDat">expDat</a></code>, <code><a
    802 href="ref_.html#$dat">$dat</a></code> and <code><a
    803 href="refD.html#datStr">datStr</a></code>.
    804 
    805 <pre><code>
    806 : (strDat "2007-06-01")
    807 -> 733134
    808 : (strDat "01.06.2007")
    809 -> NIL
    810 : (locale "DE" "de")
    811 -> NIL
    812 : (strDat "01.06.2007")
    813 -> 733134
    814 : (strDat "1.6.2007")
    815 -> 733134
    816 </code></pre>
    817 
    818 <dt><a name="strip"><code>(strip 'any) -> any</code></a>
    819 <dd>Strips all leading <code>quote</code> symbols from <code>any</code>.
    820 
    821 <pre><code>
    822 : (strip 123)
    823 -> 123
    824 : (strip '''(a))
    825 -> (a)
    826 : (strip (quote quote a b c))
    827 -> (a b c)
    828 </code></pre>
    829 
    830 <dt><a name="struct"><code>(struct 'num 'any 'any ..) -> any</code></a>
    831 <dd>Creates or extracts data structures, suitable to be passed to or returned
    832 from <code><a href="refN.html#native">native</a></code> C functions. The first
    833 <code>num</code> argument should be a native value, either a scalar, or a
    834 pointer obtained by calling functions like <code>malloc()</code>. The second
    835 argument <code>any</code> is a <a href="refN.html#natResult">result
    836 specification</a>, while all following <a
    837 href="refN.html#natItem">initialization items</a> are stored in the structure
    838 pointed to by the first argument. See also <a href="native.html">Native C
    839 Calls</a>.
    840 
    841 <pre><code>
    842 : (scl 2)
    843 -> 2
    844 
    845 ## /* We assume the following C structure */
    846 ## typedef struct value {
    847 ##    int x, y;
    848 ##    double a, b, c;
    849 ##    long z;
    850 ##    char nm[4];
    851 ## } value;
    852 
    853 # Allocate structure
    854 : (setq P (native "@" "malloc" 'N 44))
    855 -> 9204032
    856 
    857 # Store two integers, three doubles, one long, and four characters
    858 : (struct P 'N -7 -4 (1.0 0.11 0.22 0.33) (7 . 8) 65 66 67 0)
    859 -> 9204032
    860 
    861 # Extract the structure
    862 : (struct P '((I . 2) (1.0 . 3) N (C . 4)))
    863 -> ((7 4) (11 22 33) 7 ("A" "B" "C" NIL))
    864 
    865 # Do both in a single call (allowing conversions of data types)
    866 : (struct P
    867    '((I . 2) (1.0 . 3) N (C . 4))
    868    -7 -4 (1.0 0.11 0.22 0.33) (7 . 8) 65 66 67 0 )
    869 -> ((7 4) (11 22 33) 7 ("A" "B" "C" NIL))
    870 
    871 # De-allocate structure
    872 : (native "@" "free" NIL P)
    873 -> NIL
    874 </code></pre>
    875 
    876 <dt><a name="sub?"><code>(sub? 'any1 'any2) -> any2 | NIL</code></a>
    877 <dd>Returns <code>any2</code> when the string representation of
    878 <code>any1</code> is a substring of the string representation of
    879 <code>any2</code>. See also <code><a href="refP.html#pre?">pre?</a></code>.
    880 
    881 <pre><code>
    882 : (sub? "def" "abcdef")
    883 -> T
    884 : (sub? "abb" "abcdef")
    885 -> NIL
    886 : (sub? NIL "abcdef")
    887 -> T
    888 </code></pre>
    889 
    890 <dt><a name="subr"><code>(subr 'sym) -> num</code></a>
    891 <dd>Converts a Lisp-function that was previously converted with <code><a
    892 href="refE.html#expr">expr</a></code> back to a C-function.
    893 
    894 <pre><code>
    895 : car
    896 -> 67313448
    897 : (expr 'car)
    898 -> (@ (pass $385260187))
    899 : (subr 'car)
    900 -> 67313448
    901 : car
    902 -> 67313448
    903 </code></pre>
    904 
    905 <dt><a name="sum"><code>(sum 'fun 'lst ..) -> num</code></a>
    906 <dd>Applies <code>fun</code> to each element of <code>lst</code>. When
    907 additional <code>lst</code> arguments are given, their elements are also passed
    908 to <code>fun</code>. Returns the sum of all numeric values returned from
    909 <code>fun</code>.
    910 
    911 <pre><code>
    912 : (setq A 1  B 2  C 3)
    913 -> 3
    914 : (sum val '(A B C))
    915 -> 6
    916 : (sum * (3 4 5) (5 6 7))        # Vector dot product
    917 -> 74
    918 : (sum                           # Total size of symbol list values
    919    '((X)
    920       (and (pair (val X)) (size @)) )
    921    (what) )
    922 -> 32021
    923 </code></pre>
    924 
    925 <dt><a name="super"><code>(super ['any ..]) -> any</code></a>
    926 <dd>Can only be used inside methods. Sends the current message to the current
    927 object <code>This</code>, this time starting the search for a method at the
    928 superclass(es) of the class where the current method was found. See also <a
    929 href="ref.html#oop">OO Concepts</a>, <code><a
    930 href="refE.html#extra">extra</a></code>, <code><a
    931 href="refM.html#method">method</a></code>, <code><a
    932 href="refM.html#meth">meth</a></code>, <code><a
    933 href="refS.html#send">send</a></code> and <code><a
    934 href="refT.html#try">try</a></code>.
    935 
    936 <pre><code>
    937 (dm stop> ()         # 'stop>' method of current class
    938    (super)           # Call the 'stop>' method of the superclass
    939    ... )             # other things
    940 </code></pre>
    941 
    942 <dt><a name="sym"><code>(sym 'any) -> sym</code></a>
    943 <dd>Generate the printed representation of <code>any</code> into the name of a
    944 new symbol <code>sym</code>. This is the reverse operation of <code><a
    945 href="refA.html#any">any</a></code>. See also <code><a
    946 href="refN.html#name">name</a></code> and <code><a
    947 href="refS.html#str">str</a></code>.
    948 
    949 <pre><code>
    950 : (sym '(abc "Hello" 123))
    951 -> "(abc \"Hello\" 123)"
    952 </code></pre>
    953 
    954 <dt><a name="sym?"><code>(sym? 'any) -> flg</code></a>
    955 <dd>Returns <code>T</code> when the argument <code>any</code> is a symbol. See
    956 also <code><a href="refS.html#str?">str?</a></code>, <code><a
    957 href="refB.html#box?">box?</a></code> and <code><a
    958 href="refE.html#ext?">ext?</a></code>.
    959 
    960 <pre><code>
    961 : (sym? 'a)
    962 -> T
    963 : (sym? NIL)
    964 -> T
    965 : (sym? 123)
    966 -> NIL
    967 : (sym? '(a b))
    968 -> NIL
    969 </code></pre>
    970 
    971 <dt><a name="symbols"><code>(symbols) -> sym</code></a>
    972 <dt><code>(symbols 'sym1) -> sym2</code>
    973 <dt><code>(symbols 'sym1 'sym ..) -> sym2</code>
    974 <dd>(64-bit version only) Creates and manages namespaces of internal symbols: In
    975 the first form, the current namespace is returned. In the second form, the
    976 current namespace is set to <code>sym1</code>, and the previous namespace
    977 <code>sym2</code> is returned. In the third form, <code>sym1</code> is assigned
    978 a <code><a href="refB.html#balance">balance</a></code>d copy of the existing
    979 namespace(s) <code>sym</code>, and becomes the new current namespace, returning
    980 the previous namespace <code>sym2</code>. If in the third form more than one
    981 <code>sym</code> argument is given, possibly conflicting symbols in later
    982 namespaces are not interned into <code>sym2</code>. See also <code><a
    983 href="refP.html#pico">pico</a></code>, <code><a
    984 href="refL.html#local">local</a></code>, <code><a
    985 href="refI.html#import">import</a></code>, <code><a
    986 href="refI.html#intern">intern</a></code> and <code><a
    987 href="refL.html#load">load</a></code>.
    988 
    989 <pre><code>
    990 : (symbols 'myLib 'pico)
    991 -> pico
    992 myLib: (de foo (X)
    993    (bar (inc X)) )
    994 -> foo
    995 myLib: (symbols 'pico)
    996 -> myLib
    997 : (pp 'foo)
    998 (de foo . NIL)
    999 -> foo
   1000 : (pp 'myLib~foo)
   1001 (de "foo" (X)
   1002    ("bar" (inc X)) )
   1003 -> "foo"
   1004 : (symbols 'myLib)
   1005 -> pico
   1006 myLib: (pp 'foo)
   1007 (de foo (X)
   1008    (bar (inc X)) )
   1009 -> foo
   1010 myLib:
   1011 </code></pre>
   1012 
   1013 <dt><a name="sync"><code>(sync) -> flg</code></a>
   1014 <dd>Waits for pending data from all family processes. While other processes are
   1015 still sending data (via the <code><a href="refT.html#tell">tell</a></code>
   1016 mechanism), a <code>select</code> system call is executed for all file
   1017 descriptors and timers in the <code>VAL</code> of the global variable <code><a
   1018 href="refR.html#*Run">*Run</a></code>. When used in a non-database context,
   1019 <code>(tell)</code> should be called in the end to inform the parent process
   1020 that it may grant synchronization to other processes waiting for
   1021 <code>sync</code>. In a database context, where <code>sync</code> is usually
   1022 called by <code><a href="refD.html#dbSync">dbSync</a></code>, this is not
   1023 necessary because it is done internally by <code><a
   1024 href="refC.html#commit">commit</a></code> or <code><a
   1025 href="refR.html#rollback">rollback</a></code>.
   1026 
   1027 See also <code><a
   1028 href="refK.html#key">key</a></code> and <code><a
   1029 href="refW.html#wait">wait</a></code>.
   1030 
   1031 <pre><code>
   1032 : (or (lock) (sync))       # Ensure database consistency
   1033 -> T                       # (numeric process-id if lock failed)
   1034 </code></pre>
   1035 
   1036 <dt><a name="sys"><code>(sys 'any ['any]) -> sym</code></a>
   1037 <dd>Returns or sets a system environment variable.
   1038 
   1039 <pre><code>
   1040 : (sys "TERM")  # Get current value
   1041 -> "xterm"
   1042 : (sys "TERM" "vt100")  # Set new value
   1043 -> "vt100"
   1044 : (sys "TERM")
   1045 -> "vt100"
   1046 </code></pre>
   1047 
   1048 </dl>
   1049 
   1050 </body>
   1051 </html>