picolisp

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

refD.html (28442B)


      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>D</title>
      6 <link rel="stylesheet" href="doc.css" type="text/css">
      7 </head>
      8 <body>
      9 
     10 <h1>D</h1>
     11 
     12 <dl>
     13 
     14 <dt><a name="*DB"><code>*DB</code></a>
     15 <dd>A global constant holding the external symbol <code>{1}</code>, the <a
     16 href="ref.html#dbase">database</a> root. All transient symbols in a database can
     17 be reached from that root. Except during debugging, any explicit literal access
     18 to symbols in the database should be avoided, because otherwise a memory leak
     19 might occur (The garbage collector temporarily sets <code>*DB</code> to
     20 <code>NIL</code> and restores its value after collection, thus disposing of all
     21 external symbols not currently used in the program).
     22 
     23 <pre><code>
     24 : (show *DB)
     25 {1} NIL
     26    +City {P}
     27    +Person {3}
     28 -> {1}
     29 : (show '{P})
     30 {P} NIL
     31    nm (566 . {AhDx})
     32 -> {P}
     33 : (show '{3})
     34 {3} NIL
     35    tel (681376 . {Agyl})
     36    nm (1461322 . {2gu7})
     37 -> {3}
     38 </code></pre>
     39 
     40 <dt><a name="*Dbg"><code>*Dbg</code></a>
     41 <dd>A boolean variable indicating "debug mode". It can be conveniently switched
     42 on with a trailing <code>+</code> command line argument (see <a
     43 href="ref.html#invoc">Invocation</a>). When non-<code>NIL</code>, the <code><a
     44 href="ref_.html#$">$</a></code> (tracing) and <code><a
     45 href="ref_.html#!">!</a></code> (breakpoint) functions are enabled, and the
     46 current line number and file name will be stored in symbol properties by
     47 <code><a href="refD.html#de">de</a></code>, <code><a
     48 href="refD.html#def">def</a></code> and <code><a
     49 href="refD.html#dm">dm</a></code>. See also <code><a
     50 href="refD.html#debug">debug</a></code>, <code><a
     51 href="refT.html#trace">trace</a></code> and <code><a
     52 href="refL.html#lint">lint</a></code>.
     53 
     54 <pre><code>
     55 : (de foo (A B) (* A B))
     56 -> foo
     57 : (trace 'foo)
     58 -> foo
     59 : (foo 3 4)
     60  foo : 3 4
     61  foo = 12
     62 -> 12
     63 : (let *Dbg NIL (foo 3 4))
     64 -> 12
     65 </code></pre>
     66 
     67 <dt><a name="*Dbs"><code>*Dbs</code></a>
     68 <dd>A global variable holding a list of numbers (block size scale factors, as
     69 needed by <code><a href="refP.html#pool">pool</a></code>). It is typically set
     70 by <code><a href="refD.html#dbs">dbs</a></code>
     71 and <code><a href="refD.html#dbs+">dbs+</a></code>.
     72 
     73 <pre><code>
     74 : *Dbs
     75 -> (1 2 1 0 2 3 3 3)
     76 </code></pre>
     77 
     78 <dt><a name="+Date"><code>+Date</code></a>
     79 <dd>Class for calender dates (as calculated by <code><a
     80 href="refD.html#date">date</a></code>), a subclass of <code><a
     81 href="refN.html#+Number">+Number</a></code>. See also <a
     82 href="ref.html#dbase">Database</a>.
     83 
     84 <pre><code>
     85 (rel dat (+Ref +Date))  # Indexed date
     86 </code></pre>
     87 
     88 <dt><a name="+Dep"><code>+Dep</code></a>
     89 <dd>Prefix class for maintaining depenencies between <code><a
     90 href="refR.html#+relation">+relation</a></code>s. Expects a list of (symbolic)
     91 attributes that depend on this relation. Whenever this relations is cleared
     92 (receives a value of <code>NIL</code>), the dependent relations will also be
     93 cleared, triggering all required side-effects. See also <a
     94 href="ref.html#dbase">Database</a>.
     95 
     96 <p>In the following example, the index entry for the item pointing to the
     97 position (and, therefore, to the order) is cleared in case the order is deleted,
     98 or this position is deleted from the order:
     99 
    100 <pre><code>
    101 (class +Pos +Entity)                # Position class
    102 (rel ord (+Dep +Joint)              # Order of that position
    103    (itm)                               # 'itm' specifies the dependency
    104    pos (+Ord) )                        # Arguments to '+Joint'
    105 (rel itm (+Ref +Link) NIL (+Item))  # Item depends on the order
    106 </code></pre>
    107 
    108 <dt><a name="d"><code>(d) -> T</code></a>
    109 <dd>(Debug mode only) Inserts <code><a href="ref_.html#!">!</a></code>
    110 breakpoints into all subexpressions of the current breakpoint. Typically used
    111 when single-stepping a function or method with <code><a
    112 href="refD.html#debug">debug</a></code>. See also <code><a
    113 href="refU.html#u">u</a></code> and <code><a
    114 href="refU.html#unbug">unbug</a></code>.
    115 
    116 <pre><code>
    117 ! (d)                            # Debug subexpression(s) at breakpoint
    118 -> T
    119 </code></pre>
    120 
    121 <dt><a name="daemon"><code>(daemon 'sym . prg) -> fun</code></a>
    122 <dt><code>(daemon '(sym . cls) . prg) -> fun</code>
    123 <dt><code>(daemon '(sym sym2 [. cls]) . prg) -> fun</code>
    124 <dd>Inserts <code>prg</code> in the beginning of the function (first form), the
    125 method body of <code>sym</code> in <code>cls</code> (second form) or in the
    126 class obtained by <code><a href="refG.html#get">get</a></code>ing
    127 <code>sym2</code> from <code><a href="refC.html#*Class">*Class</a></code> (or
    128 <code>cls</code> if given) (third form). Built-in functions (C-function pointer)
    129 are automatically converted to Lisp expressions. See also <code><a
    130 href="refT.html#trace">trace</a></code>, <code><a
    131 href="refE.html#expr">expr</a></code>, <code><a
    132 href="refP.html#patch">patch</a></code> and <code><a
    133 href="refR.html#redef">redef</a></code>.
    134 
    135 <pre><code>
    136 : (de hello () (prinl "Hello world!"))
    137 -> hello
    138 
    139 : (daemon 'hello (prinl "# This is the hello world program"))
    140 -> (NIL (prinl "# This is the hello world program") (prinl "Hello world!"))
    141 : (hello)
    142 # This is the hello world program
    143 Hello world!
    144 -> "Hello world!"
    145 
    146 : (daemon '* (msg 'Multiplying))
    147 -> (@ (msg 'Multiplying) (pass $134532148))
    148 : *
    149 -> (@ (msg 'Multiplying) (pass $134532148))
    150 : (* 1 2 3)
    151 Multiplying
    152 -> 6
    153 </code></pre>
    154 
    155 <dt><a name="dat$"><code>(dat$ 'dat ['sym]) -> sym</code></a>
    156 <dd>Formats a <code><a href="refD.html#date">date</a></code> <code>dat</code> in
    157 ISO format, with an optional delimiter character <code>sym</code>. See also
    158 <code><a href="ref_.html#$dat">$dat</a></code>, <code><a
    159 href="refT.html#tim$">tim$</a></code>, <code><a
    160 href="refD.html#datStr">datStr</a></code> and <code><a
    161 href="refD.html#datSym">datSym</a></code>.
    162 
    163 <pre><code>
    164 : (dat$ (date))
    165 -> "20070601"
    166 : (dat$ (date) "-")
    167 -> "2007-06-01"
    168 </code></pre>
    169 
    170 <dt><a name="datStr"><code>(datStr 'dat ['flg]) -> sym</code></a>
    171 <dd>Formats a <code><a href="refD.html#date">date</a></code> according to the
    172 current <code><a href="refL.html#locale">locale</a></code>. If <code>flg</code>
    173 is non-<code>NIL</code>, the year will be formatted modulo 100. See also
    174 <code><a href="refD.html#dat$">dat$</a></code>, <code><a
    175 href="refD.html#datSym">datSym</a></code>, <code><a
    176 href="refS.html#strDat">strDat</a></code>, <code><a
    177 href="refE.html#expDat">expDat</a></code>, <code><a
    178 href="refE.html#expTel">expTel</a></code> and <code><a
    179 href="refD.html#day">day</a></code>.
    180 
    181 <pre><code>
    182 : (datStr (date))
    183 -> "2007-06-01"
    184 : (locale "DE" "de")
    185 -> NIL
    186 : (datStr (date))
    187 -> "01.06.2007"
    188 : (datStr (date) T)
    189 -> "01.06.07"
    190 </code></pre>
    191 
    192 <dt><a name="datSym"><code>(datSym 'dat) -> sym</code></a>
    193 <dd>Formats a <code><a href="refD.html#date">date</a></code> <code>dat</code> in
    194 in symbolic format (DDmmmYY). See also <code><a
    195 href="refD.html#dat$">dat$</a></code> and <code><a
    196 href="refD.html#datStr">datStr</a></code>.
    197 
    198 <pre><code>
    199 : (datSym (date))
    200 -> "01jun07"
    201 </code></pre>
    202 
    203 <dt><a name="date"><code>(date ['T]) -> dat</code></a>
    204 <dt><code>(date 'dat) -> (y m d)</code>
    205 <dt><code>(date 'y 'm 'd) -> dat | NIL</code>
    206 <dt><code>(date '(y m d)) -> dat | NIL</code>
    207 <dd>Calculates a (gregorian) calendar date. It is represented as a day number,
    208 starting first of March of the year 0 AD. When called without arguments, the
    209 current date is returned. When called with a <code>T</code> argument, the
    210 current Coordinated Universal Time (UTC) is returned. When called with a single
    211 number <code>dat</code>, it is taken as a date and a list with the corresponding
    212 year, month and day is returned. When called with three numbers (or a list of
    213 three numbers) for the year, month and day, the corresponding date is returned
    214 (or <code>NIL</code> if they do not represent a legal date). See also <code><a
    215 href="refT.html#time">time</a></code>, <code><a
    216 href="refS.html#stamp">stamp</a></code>, <code><a
    217 href="ref_.html#$dat">$dat</a></code>, <code><a
    218 href="refD.html#dat$">dat$</a></code>, <code><a
    219 href="refD.html#datSym">datSym</a></code>, <code><a
    220 href="refD.html#datStr">datStr</a></code>, <code><a
    221 href="refS.html#strDat">strDat</a></code>, <code><a
    222 href="refE.html#expDat">expDat</a></code>, <code><a
    223 href="refD.html#day">day</a></code>, <code><a
    224 href="refW.html#week">week</a></code> and <code><a
    225 href="refU.html#ultimo">ultimo</a></code>.
    226 
    227 <pre><code>
    228 : (date)                         # Today
    229 -> 730589
    230 : (date 2000 6 12)               # 12-06-2000
    231 -> 730589
    232 : (date 2000 22 5)               # Illegal date
    233 -> NIL
    234 : (date (date))                  # Today's year, month and day
    235 -> (2000 6 12)
    236 : (- (date) (date 2000 1 1))     # Number of days since first of January
    237 -> 163
    238 </code></pre>
    239 
    240 <dt><a name="day"><code>(day 'dat ['lst]) -> sym</code></a>
    241 <dd>Returns the name of the day for a given <code><a
    242 href="refD.html#date">date</a></code> <code>dat</code>, in the language of the
    243 current <code><a href="refL.html#locale">locale</a></code>. If <code>lst</code>
    244 is given, it should be a list of alternative weekday names. See also <code><a
    245 href="refW.html#week">week</a></code>, <code><a
    246 href="refD.html#datStr">datStr</a></code> and <code><a
    247 href="refS.html#strDat">strDat</a></code>.
    248 
    249 <pre><code>
    250 : (day (date))
    251 -> "Friday"
    252 : (locale "DE" "de")
    253 -> NIL
    254 : (day (date))
    255 -> "Freitag"
    256 : (day (date) '("Mo" "Tu" "We" "Th" "Fr" "Sa" "Su"))
    257 -> "Fr"
    258 </code></pre>
    259 
    260 <dt><a name="db"><code>(db 'var 'cls ['hook] 'any ['var 'any ..]) -> sym | NIL</code></a>
    261 <dd>Returns a database object of class <code>cls</code>, where the values for
    262 the <code>var</code> arguments correspond to the <code>any</code> arguments. If
    263 a matching object cannot be found, <code>NIL</code> is returned.
    264 <code>var</code>, <code>cls</code> and <code>hook</code> should specify a
    265 <code><a href="refT.html#tree">tree</a></code> for <code>cls</code> or one of
    266 its superclasses. See also <code><a href="refA.html#aux">aux</a></code>,
    267 <code><a href="refC.html#collect">collect</a></code>, <code><a
    268 href="refR.html#request">request</a></code>, <code><a
    269 href="refF.html#fetch">fetch</a></code>, <code><a
    270 href="refI.html#init">init</a></code> and <code><a
    271 href="refF.html#step">step</a></code>.
    272 
    273 <pre><code>
    274 : (db 'nr '+Item 1)
    275 -> {3-1}
    276 : (db 'nm '+Item "Main Part")
    277 -> {3-1}
    278 </code></pre>
    279 
    280 <dt><a name="db/3"><code>db/3</code></a>
    281 <dt><a name="db/4"><code>db/4</code></a>
    282 <dt><a name="db/5"><code>db/5</code></a>
    283 <dd><a href="ref.html#pilog">Pilog</a> database predicate that returns objects
    284 matching the given key/value (and optional hook) relation. The relation should
    285 be of type <code><a href="refI.html#+index">+index</a></code>. For the key
    286 pattern applies:
    287 
    288 <p><ul>
    289 <li>a symbol (string) returns all entries which start with that string
    290 <li>other atoms (numbers, external symbols) match as they are
    291 <li>cons pairs constitute a range, returning objects
    292    <ul>
    293    <li>in increasing order if the CDR is greater than the CAR
    294    <li>in decreasing order otherwise
    295    </ul>
    296 <li>other lists are matched for <code><a href="refA.html#+Aux">+Aux</a></code>
    297 key combinations
    298 </ul>
    299 
    300 <p>The optional hook can be supplied as the third argument. See also <code><a
    301 href="refS.html#select/3">select/3</a></code> and <code><a
    302 href="refR.html#remote/2">remote/2</a></code>.
    303 
    304 <pre><code>
    305 : (? (db nr +Item @Item))              # No value given
    306  @Item={3-1}
    307  @Item={3-2}
    308  @Item={3-3}
    309  @Item={3-4}
    310  @Item={3-5}
    311  @Item={3-6}
    312 -> NIL
    313 
    314 : (? (db nr +Item 2 @Item))            # Get item no. 2
    315  @Item={3-2}
    316 -> NIL
    317 
    318 : (? (db nm +Item Spare @Item) (show @Item))  # Search for "Spare.."
    319 {3-2} (+Item)
    320    pr 1250
    321    inv 100
    322    sup {2-2}
    323    nm "Spare Part"
    324    nr 2
    325  @Item={3-2}
    326 -> NIL
    327 </code></pre>
    328 
    329 <dt><a name="db:"><code>(db: cls ..) -> num</code></a>
    330 <dd>Returns the database file number for objects of the type given by the
    331 <code>cls</code> argument(s). Needed, for example, for the creation of <code><a
    332 href="refN.html#new">new</a></code> objects. See also <code><a
    333 href="refD.html#dbs">dbs</a></code>.
    334 
    335 <pre><code>
    336 : (db: +Item)
    337 -> 3
    338 </code></pre>
    339 
    340 <dt><a name="dbSync"><code>(dbSync) -> flg</code></a>
    341 <dd>Starts a database transaction, by trying to obtain a <code><a
    342 href="refL.html#lock">lock</a></code> on the database root object <code><a
    343 href="refD.html#*DB">*DB</a></code>, and then calling <code><a
    344 href="refS.html#sync">sync</a></code> to synchronize with possible changes from
    345 other processes. When all desired modifications to external symbols are done,
    346 <code>(<a href="refC.html#commit">commit</a> 'upd)</code> should be called. See
    347 also <a href="ref.html#dbase">Database</a>.
    348 
    349 <pre><code>
    350 (let? Obj (rd)             # Get object?
    351    (dbSync)                # Yes: Start transaction
    352    (put> Obj 'nm (rd))     # Update
    353    (put> Obj 'nr (rd))
    354    (put> Obj 'val (rd))
    355    (commit 'upd) )         # Close transaction
    356 </code></pre>
    357 
    358 <dt><a name="dbck"><code>(dbck ['cnt] 'flg) -> any</code></a>
    359 <dd>Performs a low-level integrity check of the current (or <code>cnt</code>'th)
    360 database file, and returns <code>NIL</code> (or the number of blocks and symbols
    361 if <code>flg</code> is non-<code>NIL</code>) if everything seems correct.
    362 Otherwise, a string indicating an error is returned. As a side effect, possibly
    363 unused blocks (as there might be when a <code><a
    364 href="refR.html#rollback">rollback</a></code> is done before <code><a
    365 href="refC.html#commit">commit</a></code>ing newly allocated (<code><a
    366 href="refN.html#new">new</a></code>) external symbols) are appended to the free
    367 list.
    368 
    369 <pre><code>
    370 : (pool "db")
    371 -> T
    372 : (dbck)
    373 -> NIL
    374 </code></pre>
    375 
    376 <dt><a name="dbs"><code>(dbs . lst)</code></a>
    377 <dd>Initializes the global variable <code><a
    378 href="refD.html#*Dbs">*Dbs</a></code>. Each element in <code>lst</code> has a
    379 number in its CAR (the block size scale factor of a database file, to be stored
    380 in <code>*Dbs</code>). The CDR elements are either classes (so that objects of
    381 that class are later stored in the corresponding file), or lists with a class in
    382 the CARs and a list of relations in the CDRs (so that index trees for these
    383 relations go into that file). See also <code><a
    384 href="refD.html#dbs+">dbs+</a></code> and <code><a
    385 href="refP.html#pool">pool</a></code>.
    386 
    387 <pre><code>
    388 (dbs
    389    (3 +Role +User +Sal)                         # 512 Prevalent objects
    390    (0 +Pos)                                     # A:64 Tiny objects
    391    (1 +Item +Ord)                               # B:128 Small objects
    392    (2 +CuSu)                                    # C:256 Normal objects
    393    (2 (+Role nm) (+User nm) (+Sal nm))          # D:256 Small indexes
    394    (4 (+CuSu nr plz tel mob))                   # E:1024 Normal indexes
    395    (4 (+CuSu nm))                               # F:1024
    396    (4 (+CuSu ort))                              # G:1024
    397    (4 (+Item nr sup pr))                        # H:1024
    398    (4 (+Item nm))                               # I:1024
    399    (4 (+Ord nr dat cus))                        # J:1024
    400    (4 (+Pos itm)) )                             # K:1024
    401 
    402 : *Dbs
    403 -> (1 2 1 0 2 4 4 4 4 4 4 4)
    404 : (get '+Item 'Dbf)
    405 -> (3 . 128)
    406 : (get '+Item 'nr 'dbf)
    407 -> (9 . 1024)
    408 </code></pre>
    409 
    410 <dt><a name="dbs+"><code>(dbs+ 'num . lst)</code></a>
    411 <dd>Extends the list of database sizes stored in <code><a
    412 href="refD.html#*Dbs">*Dbs</a></code>. <code>num</code> is the initial offset
    413 into the list. See also <code><a href="refD.html#dbs">dbs</a></code>.
    414 
    415 <pre><code>
    416 (dbs+ 9
    417    (1 +NewCls)                                  # (9 . 128)
    418    (3 (+NewCls nr nm)) )                        # (10 . 512)
    419 </code></pre>
    420 
    421 <dt><a name="de"><code>(de sym . any) -> sym</code></a>
    422 <dd>Assigns a definition to the <code>sym</code> argument, by setting its
    423 <code>VAL</code> to the <code>any</code> argument. If the symbol has already
    424 another value, a "redefined" message is issued. When the value of the global
    425 variable <a href="refD.html#*Dbg">*Dbg</a> is non-<code>NIL</code>, the current
    426 line number and file name (if any) are stored in the <code>*Dbg</code> property
    427 of <code>sym</code>. <code>de</code> is the standard way to define a function.
    428 See also <code><a href="refD.html#def">def</a></code>, <code><a
    429 href="refD.html#dm">dm</a></code> and <code><a
    430 href="refU.html#undef">undef</a></code>.
    431 
    432 <pre><code>
    433 : (de foo (X Y) (* X (+ X Y)))  # Define a function
    434 -> foo
    435 : (foo 3 4)
    436 -> 21
    437 
    438 : (de *Var . 123)  # Define a variable value
    439 : *Var
    440 -> 123
    441 </code></pre>
    442 
    443 <dt><a name="debug"><code>(debug 'sym) -> T</code></a>
    444 <dt><code>(debug 'sym 'cls) -> T</code>
    445 <dt><code>(debug '(sym . cls)) -> T</code>
    446 <dd>(Debug mode only) Inserts a <code><a href="ref_.html#!">!</a></code>
    447 breakpoint function call at the beginning and all top-level expressions of the
    448 function or method body of <code>sym</code>, to allow a stepwise execution.
    449 Typing <code>(<a href="refD.html#d">d</a>)</code> at a breakpoint will also
    450 debug the current subexpression, and <code>(<a href="refE.html#e">e</a>)</code>
    451 will evaluate the current subexpression. The current subexpression is stored in
    452 the global variable <code><a href="ref_.html#^">^</a></code>. See also <code><a
    453 href="refU.html#unbug">unbug</a></code>, <code><a
    454 href="refD.html#*Dbg">*Dbg</a></code>, <code><a
    455 href="refT.html#trace">trace</a></code> and <code><a
    456 href="refL.html#lint">lint</a></code>.
    457 
    458 <pre><code>
    459 : (de tst (N)                    # Define tst
    460    (println (+ 3 N)) )
    461 -> tst
    462 : (debug 'tst)                   # Set breakpoints
    463 -> T
    464 : (pp 'tst)
    465 (de tst (N)
    466    (! println (+ 3 N)) )         # Breakpoint '!'
    467 -> tst
    468 : (tst 7)                        # Execute
    469 (println (+ 3 N))                # Stopped at beginning of 'tst'
    470 ! (d)                            # Debug subexpression
    471 -> T
    472 !                                # Continue
    473 (+ 3 N)                          # Stopped in subexpression
    474 ! N                              # Inspect variable 'N'
    475 -> 7
    476 !                                # Continue
    477 10                               # Output of print statement
    478 -> 10                            # Done
    479 : (unbug 'tst)
    480 -> T
    481 : (pp 'tst)                      # Restore to original
    482 (de tst (N)
    483    (println (+ 3 N)) )
    484 -> tst
    485 </code></pre>
    486 
    487 <dt><a name="dec"><code>(dec 'num) -> num</code></a>
    488 <dt><code>(dec 'var ['num]) -> num</code>
    489 <dd>The first form returns the value of <code>num</code> decremented by 1. The
    490 second form decrements the <code>VAL</code> of <code>var</code> by 1, or by
    491 <code>num</code>. If the first argument is <code>NIL</code>, it is returned
    492 immediately. <code>(dec Num)</code> is equivalent to <code>(- Num 1)</code> and
    493 <code>(dec 'Var)</code> is equivalent to <code>(set 'Var (- Var 1))</code>. See
    494 also <code><a href="refI.html#inc">inc</a></code> and <code><a
    495 href="ref_.html#-">-</a></code>.
    496 
    497 <pre><code>
    498 : (dec -1)
    499 -> -2
    500 : (dec 7)
    501 -> 6
    502 : (setq N 7)
    503 -> 7
    504 : (dec 'N)
    505 -> 6
    506 : (dec 'N 3)
    507 -> 3
    508 </code></pre>
    509 
    510 <dt><a name="def"><code>(def 'sym 'any) -> sym</code></a>
    511 <dt><code>(def 'sym1 'sym2 'any) -> sym1</code>
    512 <dd>The first form assigns a definition to the first <code>sym</code> argument,
    513 by setting its <code>VAL</code>'s to <code>any</code>. The second form defines a
    514 property value <code>any</code> for the first argument's <code>sym2</code> key.
    515 If any of these values existed and was changed in the process, a "redefined"
    516 message is issued. When the value of the global variable <a
    517 href="refD.html#*Dbg">*Dbg</a> is non-<code>NIL</code>, the current line number
    518 and file name (if any) are stored in the <code>*Dbg</code> property of
    519 <code>sym</code>. See also <code><a href="refD.html#de">de</a></code> and
    520 <code><a href="refD.html#dm">dm</a></code>.
    521 
    522 <pre><code>
    523 : (def 'b '((X Y) (* X (+ X Y))))
    524 -> b
    525 : (def 'b 999)
    526 # b redefined
    527 -> b
    528 </code></pre>
    529 
    530 <dt><a name="default"><code>(default var 'any ..) -> any</code></a>
    531 <dd>Stores new values <code>any</code> in the <code>var</code> arguments only if
    532 their current values are <code>NIL</code>. Otherwise, their values are left
    533 unchanged. In any case, the last <code>var</code>'s value is returned.
    534 <code>default</code> is used typically in functions to initialize optional
    535 arguments.
    536 
    537 <pre><code>
    538 : (de foo (A B)               # Function with two optional arguments
    539    (default  A 1  B 2)        # The default values are 1 and 2
    540    (list A B) )
    541 -> foo
    542 : (foo 333 444)               # Called with two arguments
    543 -> (333 444)
    544 : (foo 333)                   # Called with one arguments
    545 -> (333 2)
    546 : (foo)                       # Called without arguments
    547 -> (1 2)
    548 </code></pre>
    549 
    550 <dt><a name="del"><code>(del 'any 'var) -> lst</code></a>
    551 <dd>Deletes <code>any</code> from the list in the value of <code>var</code>, and
    552 returns the remaining list. <code>(del 'any 'var)</code> is equivalent to
    553 <code>(set 'var (delete 'any var))</code>. See also <code><a
    554 href="refD.html#delete">delete</a></code>, <code><a
    555 href="refC.html#cut">cut</a></code> and <code><a
    556 href="refP.html#pop">pop</a></code>.
    557 
    558 <pre><code>
    559 : (setq S '((a b c) (d e f)))
    560 -> ((a b c) (d e f))
    561 : (del '(d e f) 'S)
    562 -> ((a b c))
    563 : (del 'b S)
    564 -> (a c)
    565 </code></pre>
    566 
    567 <dt><a name="delete"><code>(delete 'any 'lst) -> lst</code></a>
    568 <dd>Deletes <code>any</code> from <code>lst</code>. If <code>any</code> is
    569 contained more than once in <code>lst</code>, only the first occurrence is
    570 deleted. See also <code><a href="refD.html#delq">delq</a></code>, <code><a
    571 href="refR.html#remove">remove</a></code> and <code><a
    572 href="refI.html#insert">insert</a></code>.
    573 
    574 <pre><code>
    575 : (delete 2 (1 2 3))
    576 -> (1 3)
    577 : (delete (3 4) '((1 2) (3 4) (5 6) (3 4)))
    578 -> ((1 2) (5 6) (3 4))
    579 </code></pre>
    580 
    581 <dt><a name="delete/3"><code>delete/3</code></a>
    582 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if deleting the
    583 first argument from the list in the second argument is equal to the third
    584 argument. See also <code><a href="refD.html#delete">delete</a></code> and
    585 <code><a href="refM.html#member/2">member/2</a></code>.
    586 
    587 <pre><code>
    588 : (? (delete b (a b c) @X))
    589  @X=(a c)
    590 -> NIL
    591 </code></pre>
    592 
    593 <dt><a name="delq"><code>(delq 'any 'lst) -> lst</code></a>
    594 <dd>Deletes <code>any</code> from <code>lst</code>. If <code>any</code> is
    595 contained more than once in <code>lst</code>, only the first occurrence is
    596 deleted. <code><a href="ref_.html#==">==</a></code> is used for comparison
    597 (pointer equality). See also <code><a href="refD.html#delete">delete</a></code>,
    598 <code><a href="refA.html#asoq">asoq</a></code>, <code><a
    599 href="refM.html#memq">memq</a></code>, <code><a
    600 href="refM.html#mmeq">mmeq</a></code> and <a href="ref.html#cmp">Comparing</a>.
    601 
    602 <pre><code>
    603 : (delq 'b '(a b c))
    604 -> (a c)
    605 : (delq (2) (1 (2) 3))
    606 -> (1 (2) 3)
    607 </code></pre>
    608 
    609 <dt><a name="dep"><code>(dep 'cls) -> cls</code></a>
    610 <dd>(Debug mode only) Displays the "dependencies" of <code>cls</code>, i.e. the
    611 tree of superclasses and the tree of subclasses. See also <a
    612 href="ref.html#oop">OO Concepts</a>, <code><a
    613 href="refM.html#methods">methods</a></code>, <code><a
    614 href="refC.html#class">class</a></code> and <code><a
    615 href="refC.html#can">can</a></code>.
    616 
    617 <pre><code>
    618 : (dep '+Number)           # Dependencies of '+Number'
    619    +relation               # Single superclass is '+relation'
    620 +Number
    621    +Date                   # Subclasses are '+Date' and '+Time'
    622    +Time
    623 -> +Number
    624 </code></pre>
    625 
    626 <dt><a name="depth"><code>(depth 'lst) -> (cnt1 . cnt2)</code></a>
    627 <dd>Returns the maximal (<code>cnt1</code>) and the average (<code>cnt2</code>)
    628 "depth" of a tree structure as maintained by <code><a
    629 href="refI.html#idx">idx</a></code>. See also <code><a
    630 href="refL.html#length">length</a></code> and <code><a
    631 href="refS.html#size">size</a></code>.
    632 
    633 <pre><code>
    634 : (off X)                                    # Clear variable
    635 -> NIL
    636 : (for N (1 2 3 4 5 6 7) (idx 'X N T))       # Build a degenerated tree
    637 -> NIL
    638 : X
    639 -> (1 NIL 2 NIL 3 NIL 4 NIL 5 NIL 6 NIL 7)   # Only right branches
    640 : (depth X)
    641 -> (7 . 4)                                   # Depth is 7, average 4
    642 </code></pre>
    643 
    644 <dt><a name="diff"><code>(diff 'lst 'lst) -> lst</code></a>
    645 <dd>Returns the difference of the <code>lst</code> arguments. See also <code><a
    646 href="refS.html#sect">sect</a></code>.
    647 
    648 <pre><code>
    649 : (diff (1 2 3 4 5) (2 4))
    650 -> (1 3 5)
    651 : (diff (1 2 3) (1 2 3))
    652 -> NIL
    653 </code></pre>
    654 
    655 <dt><a name="different/2"><code>different/2</code></a>
    656 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the two
    657 arguments are different. See also <code><a
    658 href="refE.html#equal/2">equal/2</a></code>.
    659 
    660 <pre><code>
    661 : (? (different 3 4))
    662 -> T
    663 </code></pre>
    664 
    665 <dt><a name="dir"><code>(dir ['any] ['flg]) -> lst</code></a>
    666 <dd>Returns a list of all filenames in the directory <code>any</code>. Names
    667 starting with a dot '<code>.</code>' are ignored, unless <code>flg</code> is
    668 non-<code>NIL</code>. See also <code><a href="refC.html#cd">cd</a></code> and
    669 <code><a href="refI.html#info">info</a></code>.
    670 
    671 <pre><code>
    672 : (filter '((F) (tail '(. c) (chop F))) (dir "src/"))
    673 -> ("main.c" "subr.c" "gc.c" "io.c" "big.c" "sym.c" "tab.c" "flow.c" ..
    674 </code></pre>
    675 
    676 <dt><a name="dirname"><code>(dirname 'any) -> sym</code></a>
    677 <dd>Returns the directory part of a path name <code>any</code>. See also
    678 <code><a href="refB.html#basename">basename</a></code> and <code><a
    679 href="refP.html#path">path</a></code>.
    680 
    681 <pre><code>
    682 : (dirname "a/b/c/d")
    683 -> "a/b/c/"
    684 </code></pre>
    685 
    686 <dt><a name="dm"><code>(dm sym . fun|cls2) -> sym</code></a>
    687 <dt><code>(dm (sym . cls) . fun|cls2) -> sym</code>
    688 <dt><code>(dm (sym sym2 [. cls]) . fun|cls2) -> sym</code>
    689 <dd>Defines a method for the message <code>sym</code> in the current class,
    690 implicitly given by the value of the global variable <code><a
    691 href="refC.html#*Class">*Class</a></code>, or - in the second form - for the
    692 explicitly given class <code>cls</code>. In the third form, the class object is
    693 obtained by <code><a href="refG.html#get">get</a></code>ing <code>sym2</code>
    694 from <code><a href="refC.html#*Class">*Class</a></code> (or <code>cls</code> if
    695 given). If the method for that class existed and was changed in the process, a
    696 "redefined" message is issued. If - instead of a method <code>fun</code> - a
    697 symbol specifying another class <code>cls2</code> is given, the method from that
    698 class is used (explicit inheritance). When the value of the global variable <a
    699 href="refD.html#*Dbg">*Dbg</a> is non-<code>NIL</code>, the current line number
    700 and file name (if any) are stored in the <code>*Dbg</code> property of
    701 <code>sym</code>. See also <a href="ref.html#oop">OO Concepts</a>, <code><a
    702 href="refD.html#de">de</a></code>, <code><a
    703 href="refU.html#undef">undef</a></code>, <a href="refC.html#class">class</a>, <a
    704 href="refR.html#rel">rel</a>, <a href="refV.html#var">var</a>, <a
    705 href="refM.html#method">method</a>, <a href="refS.html#send">send</a> and <a
    706 href="refT.html#try">try</a>.
    707 
    708 <pre><code>
    709 : (dm start> ()
    710    (super)
    711    (mapc 'start> (: fields))
    712    (mapc 'start> (: arrays)) )
    713 
    714 : (dm foo> . +OtherClass)  # Explicitly inherit 'foo>' from '+OtherClass'
    715 </code></pre>
    716 
    717 <dt><a name="do"><code>(do 'flg|num ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any</code></a>
    718 <dd>Counted loop with multiple conditional exits: The body is executed at most
    719 <code>num</code> times (or never (if the first argument is <code>NIL</code>), or
    720 an infinite number of times (if the first argument is <code>T</code>)). If a
    721 clause has <code>NIL</code> or <code>T</code> as its CAR, the clause's second
    722 element is evaluated as a condition and - if the result is <code>NIL</code> or
    723 non-<code>NIL</code>, respectively - the <code>prg</code> is executed and the
    724 result returned. Otherwise (if count drops to zero), the result of the last
    725 expression is returned. See also <code><a href="refL.html#loop">loop</a></code>
    726 and <code><a href="refF.html#for">for</a></code>.
    727 
    728 <pre><code>
    729 : (do 4 (printsp 'OK))
    730 OK OK OK OK -> OK
    731 : (do 4 (printsp 'OK) (T (= 3 3) (printsp 'done)))
    732 OK done -> done
    733 </code></pre>
    734 
    735 <dt><a name="doc"><code>(doc ['sym1] ['sym2])</code></a>
    736 <dd>(Debug mode only) Opens a browser, and tries to display the reference
    737 documentation for <code>sym1</code>. <code>sym2</code> may be the name of a
    738 browser. If not given, the value of the environment variable
    739 <code>BROWSER</code>, or the <code>w3m</code> browser is tried. If
    740 <code>sym1</code> is <code>NIL</code>, the <a href="ref.html">PicoLisp
    741 Reference</a> manual is opened. See also <a href="ref.html#fun">Function
    742 Reference</a> and <code><a href="refV.html#vi">vi</a></code>.
    743 
    744 <pre><code>
    745 : (doc '+)  # Function reference
    746 -> T
    747 : (doc '+relation)  # Class reference
    748 -> T
    749 : (doc)  # Reference manual
    750 -> T
    751 :  (doc 'vi "firefox")  # Use alternative browser
    752 -> T
    753 </code></pre>
    754 
    755 </dl>
    756 
    757 </body>
    758 </html>