picolisp

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

refR.html (24306B)


      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>R</title>
      6 <link rel="stylesheet" href="doc.css" type="text/css">
      7 </head>
      8 <body>
      9 
     10 <h1>R</h1>
     11 
     12 <dl>
     13 
     14 <dt><a name="*Run"><code>*Run</code></a>
     15 <dd>This global variable can hold a list of <code>prg</code> expressions which
     16 are used during <code><a href="refK.html#key">key</a></code>, <code><a
     17 href="refS.html#sync">sync</a></code>, <code><a
     18 href="refW.html#wait">wait</a></code> and <code><a
     19 href="refL.html#listen">listen</a></code>. The first element of each expression
     20 must either be a positive number (thus denoting a file descriptor to wait for)
     21 or a negative number (denoting a timeout value in milliseconds (in that case
     22 another number must follow to hold the remaining time)). A <code>select</code>
     23 system call is performed with these values, and the corresponding
     24 <code>prg</code> body is executed when input data are available or when a
     25 timeout occurred. See also <code><a href="refT.html#task">task</a></code>.
     26 
     27 <pre><code>
     28 : (de *Run (-2000 0 (println '2sec)))     # Install 2-sec-timer
     29 -> *Run
     30 : 2sec                                    # Prints "2sec" every 2 seconds
     31 2sec
     32 2sec
     33                                           # (Ctrl-D) Exit
     34 $
     35 </code></pre>
     36 
     37 <dt><a name="+Ref"><code>+Ref</code></a>
     38 <dd>Prefix class for maintaining non-unique indexes to <code><a
     39 href="refR.html#+relation">+relation</a></code>s, a subclass of <code><a
     40 href="refI.html#+index">+index</a></code>. Accepts an optional argument for a
     41 <code><a href="refH.html#+Hook">+Hook</a></code> attribute. See also <a
     42 href="ref.html#dbase">Database</a>.
     43 
     44 <pre><code>
     45 (rel tel (+Fold +Ref +String))  # Phone number with folded, non-unique index
     46 </code></pre>
     47 
     48 <dt><a name="+Ref2"><code>+Ref2</code></a>
     49 <dd>Prefix class for maintaining a secondary ("backing") index to <code><a
     50 href="refR.html#+relation">+relation</a></code>s. Can only be used as a prefix
     51 class to <code><a href="refK.html#+Key">+Key</a></code> or <code><a
     52 href="refR.html#+Ref">+Ref</a></code>. It maintains an index in the current
     53 (sub)class, in addition to that in one of the superclasses, to allow
     54 (sub)class-specific queries. See also <a
     55 href="ref.html#dbase">Database</a>.
     56 
     57 <pre><code>
     58 (class +Ord +Entity)             # Order class
     59 (rel nr (+Need +Key +Number))    # Order number
     60 ...
     61 (class +EuOrd +Ord)              # EU-specific order subclass
     62 (rel nr (+Ref2 +Key +Number))    # Order number with backing index
     63 </code></pre>
     64 
     65 <dt><a name="+relation"><code>+relation</code></a>
     66 <dd>Abstract base class of all database releations. Relation objects are usually
     67 defined with <code><a href="refR.html#rel">rel</a></code>. The class hierarchy
     68 includes the classes <code><a href="refA.html#+Any">+Any</a></code>, <code><a
     69 href="refB.html#+Bag">+Bag</a></code>, <code><a
     70 href="refB.html#+Bool">+Bool</a></code>, <code><a
     71 href="refN.html#+Number">+Number</a></code>, <code><a
     72 href="refD.html#+Date">+Date</a></code>, <code><a
     73 href="refT.html#+Time">+Time</a></code>, <code><a
     74 href="refS.html#+Symbol">+Symbol</a></code>, <code><a
     75 href="refS.html#+String">+String</a></code>, <code><a
     76 href="refL.html#+Link">+Link</a></code>, <code><a
     77 href="refJ.html#+Joint">+Joint</a></code> and <code><a
     78 href="refB.html#+Blob">+Blob</a></code>, and the prefix classes <code><a
     79 href="refH.html#+Hook">+Hook</a></code>, <code><a
     80 href="refH.html#+Hook2">+Hook2</a></code>, <code><a
     81 href="refI.html#+index">+index</a></code>, <code><a
     82 href="refK.html#+Key">+Key</a></code>, <code><a
     83 href="refR.html#+Ref">+Ref</a></code>, <code><a
     84 href="refR.html#+Ref2">+Ref2</a></code>, <code><a
     85 href="refI.html#+Idx">+Idx</a></code>, <code><a
     86 href="refI.html#+IdxFold">+IdxFold</a></code>, <code><a
     87 href="refS.html#+Sn">+Sn</a></code>, <code><a
     88 href="refF.html#+Fold">+Fold</a></code>, <code><a
     89 href="refA.html#+Aux">+Aux</a></code>, <code><a
     90 href="refU.html#+UB">+UB</a></code>, <code><a
     91 href="refD.html#+Dep">+Dep</a></code>, <code><a
     92 href="refL.html#+List">+List</a></code>, <code><a
     93 href="refN.html#+Need">+Need</a></code>, <code><a
     94 href="refM.html#+Mis">+Mis</a></code> and <code><a
     95 href="refA.html#+Alt">+Alt</a></code>. See also <a
     96 href="ref.html#dbase">Database</a> and <code><a
     97 href="refE.html#+Entity">+Entity</a></code>.
     98 
     99 <p><a name="relationMesssages">Messages</a> to relation objects include
    100 
    101 <pre><code>
    102 mis> (Val Obj)       # Return error if mismatching type or value
    103 has> (Val X)         # Check if the value is present
    104 put> (Obj Old New)   # Put new value
    105 rel> (Obj Old New)   # Maintain relational strutures
    106 lose> (Obj Val)      # Delete relational structures
    107 keep> (Obj Val)      # Restore deleted relational structures
    108 zap> (Obj Val)       # Clean up relational structures
    109 </code></pre>
    110 
    111 <dt><a name="rand"><code>(rand ['cnt1 'cnt2] | ['T]) -> cnt | flg</code></a>
    112 <dd>Returns a pseudo random number in the range cnt1 .. cnt2 (or -2147483648 ..
    113 +2147483647 if no arguments are given). If the argument is <code>T</code>, a
    114 boolean value <code>flg</code> is returned. See also <code><a
    115 href="refS.html#seed">seed</a></code>.
    116 
    117 <pre><code>
    118 : (rand 3 9)
    119 -> 3
    120 : (rand 3 9)
    121 -> 7
    122 </code></pre>
    123 
    124 <dt><a name="range"><code>(range 'num1 'num2 ['num3]) -> lst</code></a>
    125 <dd>Produces a list of numbers in the range <code>num1</code> through
    126 <code>num2</code>. When <code>num3</code> is non-<code>NIL</code>), it is used
    127 to increment <code>num1</code> (if it is smaller than <code>num2</code>) or to
    128 decrement <code>num1</code> (if it is greater than <code>num2</code>). See also
    129 <code><a href="refN.html#need">need</a></code>.
    130 
    131 <pre><code>
    132 : (range 1 6)
    133 -> (1 2 3 4 5 6)
    134 : (range 6 1)
    135 -> (6 5 4 3 2 1)
    136 : (range -3 3)
    137 -> (-3 -2 -1 0 1 2 3)
    138 : (range 3 -3 2)
    139 -> (3 1 -1 -3)
    140 </code></pre>
    141 
    142 <dt><a name="range/3"><code>range/3</code></a>
    143 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the first
    144 argument is in the range of the result of applying the <code><a
    145 href="refG.html#get">get</a></code> algorithm to the following arguments.
    146 Typically used as filter predicate in <code><a
    147 href="refS.html#select/3">select/3</a></code> database queries. See also
    148 <code><a href="ref.html#cmp">Comparing</a></code>, <code><a
    149 href="refI.html#isa/2">isa/2</a></code>, <code><a
    150 href="refS.html#same/3">same/3</a></code>, <code><a
    151 href="refB.html#bool/3">bool/3</a></code>, <code><a
    152 href="refH.html#head/3">head/3</a></code>, <code><a
    153 href="refF.html#fold/3">fold/3</a></code>, <code><a
    154 href="refP.html#part/3">part/3</a></code> and <code><a
    155 href="refT.html#tolr/3">tolr/3</a></code>.
    156 
    157 <pre><code>
    158 : (?
    159    @Nr (1 . 5)  # Numbers between 1 and 5
    160    @Nm "part"
    161    (select (@Item)
    162       ((nr +Item @Nr) (nm +Item @Nm))
    163       (range @Nr @Item nr)
    164       (part @Nm @Item nm) ) )
    165  @Nr=(1 . 5) @Nm="part" @Item={3-1}
    166  @Nr=(1 . 5) @Nm="part" @Item={3-2}
    167 -> NIL
    168 </code></pre>
    169 
    170 <dt><a name="rank"><code>(rank 'any 'lst ['flg]) -> lst</code></a>
    171 <dd>Searches a ranking list. <code>lst</code> should be sorted. Returns the
    172 element from <code>lst</code> with a maximal CAR less or equal to
    173 <code>any</code> (if <code>flg</code> is <code>NIL</code>), or with a minimal
    174 CAR greater or equal to <code>any</code> (if <code>flg</code> is
    175 non-<code>NIL</code>), or <code>NIL</code> if no match is found. See also
    176 <code><a href="refA.html#assoc">assoc</a></code> and <a
    177 href="ref.html#cmp">Comparing</a>.
    178 
    179 <pre><code>
    180 : (rank 0 '((1 . a) (100 . b) (1000 . c)))
    181 -> NIL
    182 : (rank 50 '((1 . a) (100 . b) (1000 . c)))
    183 -> (1 . a)
    184 : (rank 100 '((1 . a) (100 . b) (1000 . c)))
    185 -> (100 . b)
    186 : (rank 300 '((1 . a) (100 . b) (1000 . c)))
    187 -> (100 . b)
    188 : (rank 9999 '((1 . a) (100 . b) (1000 . c)))
    189 -> (1000 . c)
    190 : (rank 50 '((1000 . a) (100 . b) (1 . c)) T)
    191 -> (100 . b)
    192 </code></pre>
    193 
    194 <dt><a name="raw"><code>(raw ['flg]) -> flg</code></a>
    195 <dd>Console mode control function. When called without arguments, it returns the
    196 current console mode (<code>NIL</code> for "cooked mode"). Otherwise, the
    197 console is set to the new state. See also <code><a
    198 href="refK.html#key">key</a></code>.
    199 
    200 <pre><code>
    201 $ pil
    202 : (raw)
    203 -> NIL
    204 $ pil +
    205 : (raw)
    206 -> T
    207 </code></pre>
    208 
    209 <dt><a name="rc"><code>(rc 'sym 'any1 ['any2]) -> any</code></a>
    210 <dd>Fetches a value from a resource file <code>sym</code>, or stores a value
    211 <code>any2</code> in that file, using a key <code>any1</code>. All values are
    212 stored in a list in the file, using <code><a
    213 href="refA.html#assoc">assoc</a></code>. During the whole operation, the file is
    214 exclusively locked with <code><a href="refC.html#ctl">ctl</a></code>.
    215 
    216 <pre><code>
    217 : (info "a.rc")               # File exists?
    218 -> NIL                        # No
    219 : (rc "a.rc" 'a 1)            # Store 1 for 'a'
    220 -> 1
    221 : (rc "a.rc" 'b (2 3 4))      # Store (2 3 4) for 'b'
    222 -> (2 3 4)
    223 : (rc "a.rc" 'c 'b)           # Store 'b' for 'c'
    224 -> b
    225 : (info "a.rc")               # Check file
    226 -> (28 733124 . 61673)
    227 : (in "a.rc" (echo))          # Display it
    228 ((c . b) (b 2 3 4) (a . 1))
    229 -> T
    230 : (rc "a.rc" 'c)              # Fetch value for 'c'
    231 -> b
    232 : (rc "a.rc" @)               # Fetch value for 'b'
    233 -> (2 3 4)
    234 </code></pre>
    235 
    236 <dt><a name="rd"><code>(rd ['sym]) -> any</code></a>
    237 <dt><code>(rd 'cnt) -> num | NIL</code>
    238 <dd>Binary read: Reads one item from the current input channel in encoded binary
    239 format. When called with a <code>cnt</code> argument (second form), that number
    240 of raw bytes (in big endian format if <code>cnt</code> is positive, otherwise
    241 little endian) is read as a single number. Upon end of file, if the
    242 <code>sym</code> argument is given, it is returned, otherwise <code>NIL</code>.
    243 See also <code><a href="refP.html#pr">pr</a></code>, <code><a
    244 href="refT.html#tell">tell</a></code>, <code><a
    245 href="refH.html#hear">hear</a></code> and <code><a
    246 href="refW.html#wr">wr</a></code>.
    247 
    248 <pre><code>
    249 : (out "x" (pr 'abc "EOF" 123 "def"))
    250 -> "def"
    251 : (in "x" (rd))
    252 -> abc
    253 : (in "x"
    254    (make
    255       (use X
    256          (until (== "EOF" (setq X (rd "EOF")))  # '==' detects end of file
    257             (link X) ) ) ) )
    258 -> (abc "EOF" 123 "def")  # as opposed to reading a symbol "EOF"
    259 
    260 : (in "/dev/urandom" (rd 20))
    261 -> 396737673456823753584720194864200246115286686486
    262 </code></pre>
    263 
    264 <dt><a name="read"><code>(read ['sym1 ['sym2]]) -> any</code></a>
    265 <dd>Reads one item from the current input channel. <code>NIL</code> is returned
    266 upon end of file. When called without arguments, an arbitrary Lisp expression is
    267 read. Otherwise, a token (a number, an internal symbol, a transient symbol (for
    268 punctuation), or a list of symbols (for a string)) is read. In that case,
    269 <code>sym1</code> specifies which set of characters to accept for continuous
    270 symbol names (in addition to the standard alphanumerical characters), and
    271 <code>sym2</code> an optional comment character. See also <code><a
    272 href="refA.html#any">any</a></code>, <code><a
    273 href="refS.html#str">str</a></code>, <code><a
    274 href="refL.html#line">line</a></code>, <code><a
    275 href="refS.html#skip">skip</a></code> and <code><a
    276 href="refE.html#eof">eof</a></code>.
    277 
    278 <pre><code>
    279 : (list (read) (read) (read))    # Read three things from console
    280 123                              # a number
    281 abcd                             # a symbol
    282 (def                             # and a list
    283 ghi
    284 jkl
    285 )
    286 -> (123 abcd (def ghi jkl))
    287 : (make (while (read "_" "#") (link @)))
    288 abc = def_ghi("xyz"+-123) # Comment
    289 NIL
    290 -> (abc "=" def_ghi "(" ("x" "y" "z") "+" "-" 123 ")")
    291 </code></pre>
    292 
    293 <dt><a name="recur"><code>(recur fun) -> any</code></a>
    294 <dt><a name="recurse"><code>(recurse ..) -> any</code></a>
    295 <dd>Implements anonymous recursion, by defining the function
    296 <code>recurse</code> on the fly. During the execution of <code>fun</code>, the
    297 symbol <code>recurse</code> is bound to the function definition
    298 <code>fun</code>. See also <code><a href="refL.html#let">let</a></code> and
    299 <code><a href="ref.html#lambda">lambda</a></code>.
    300 
    301 <pre><code>
    302 : (de fibonacci (N)
    303    (when (lt0 N)
    304       (quit "Bad fibonacci" N) )
    305    (recur (N)
    306       (if (> 2 N)
    307          1
    308          (+
    309             (recurse (dec N))
    310             (recurse (- N 2)) ) ) ) )
    311 -> fibonacci
    312 : (fibonacci 22)
    313 -> 28657
    314 : (fibonacci -7)
    315 -7 -- Bad fibonacci
    316 </code></pre>
    317 
    318 <dt><a name="redef"><code>(redef sym . fun) -> sym</code></a>
    319 <dd>Redefines <code>sym</code> in terms of itself. The current definition is
    320 saved in a new symbol, which is substituted for each occurrence of
    321 <code>sym</code> in <code>fun</code>, and which is also returned. See also
    322 <code><a href="refD.html#de">de</a></code>, <code><a
    323 href="refU.html#undef">undef</a></code>, <code><a
    324 href="refD.html#daemon">daemon</a></code> and <code><a
    325 href="refP.html#patch">patch</a></code>.
    326 
    327 <pre><code>
    328 : (de hello () (prinl "Hello world!"))
    329 -> hello
    330 : (pp 'hello)
    331 (de hello NIL
    332    (prinl "Hello world!") )
    333 -> hello
    334 
    335 : (redef hello (A B)
    336    (println 'Before A)
    337    (prog1 (hello) (println 'After B)) )
    338 -> "hello"
    339 : (pp 'hello)
    340 (de hello (A B)
    341    (println 'Before A)
    342    (prog1 ("hello") (println 'After B)) )
    343 -> hello
    344 : (hello 1 2)
    345 Before 1
    346 Hello world!
    347 After 2
    348 -> "Hello world!"
    349 
    350 : (redef * @
    351    (msg (rest))
    352    (pass *) )
    353 -> "*"
    354 : (* 1 2 3)
    355 (1 2 3)
    356 -> 6
    357 
    358 : (redef + @
    359    (pass (ifn (num? (next)) pack +) (arg)) )
    360 -> "+"
    361 : (+ 1 2 3)
    362 -> 6
    363 : (+ "a" 'b '(c d e))
    364 -> "abcde"
    365 
    366 </code></pre>
    367 
    368 <dt><a name="rel"><code>(rel var lst [any ..]) -> any</code></a>
    369 <dd>Defines a relation for <code>var</code> in the current class <code><a
    370 href="refC.html#*Class">*Class</a></code>, using <code>lst</code> as the list of
    371 classes for that relation, and possibly additional arguments <code>any</code>
    372 for its initialization. See also <a href="ref.html#dbase">Database</a>, <code><a
    373 href="refC.html#class">class</a></code>, <code><a
    374 href="refE.html#extend">extend</a></code>, <code><a
    375 href="refD.html#dm">dm</a></code> and <code><a
    376 href="refV.html#var">var</a></code>.
    377 
    378 <pre><code>
    379 (class +Person +Entity)
    380 (rel nm  (+List +Ref +String))            # Names
    381 (rel tel (+Ref +String))                  # Telephone
    382 (rel adr (+Joint) prs (+Address))         # Address
    383 
    384 (class +Address +Entity)
    385 (rel cit (+Need +Hook +Link) (+City))     # City
    386 (rel str (+List +Ref +String) cit)        # Street
    387 (rel prs (+List +Joint) adr (+Person))    # Inhabitants
    388 
    389 (class +City +Entity)
    390 (rel nm  (+List +Ref +String))            # Zip / Names
    391 </code></pre>
    392 
    393 <dt><a name="release"><code>(release 'sym) -> NIL</code></a>
    394 <dd>Releases the mutex represented by the file 'sym'. This is the reverse
    395 operation of <code><a href="refA.html#acquire">acquire</a></code>.
    396 
    397 <pre><code>
    398 : (release "sema1")
    399 -> NIL
    400 </code></pre>
    401 
    402 <dt><a name="remote/2"><code>remote/2</code></a>
    403 <dd><a href="ref.html#pilog">Pilog</a> predicate for remote database queries. It
    404 takes a list and an arbitrary number of clauses. The list should contain a Pilog
    405 variable for the result in the CAR, and a list of resources in the CDR. The
    406 clauses will be evaluated on remote machines according to these resources. Each
    407 resource must be a cons pair of two functions, an "out" function in the CAR, and
    408 an "in" function in the CDR. See also <code><a
    409 href="refE.html#*Ext">*Ext</a></code>, <code><a
    410 href="refS.html#select/3">select/3</a></code> and <code><a
    411 href="refD.html#db/3">db/3</a></code>.
    412 
    413 <pre><code>
    414 (setq *Ext           # Set up external offsets
    415    (mapcar
    416       '((@Host @Ext)
    417          (cons @Ext
    418             (curry (@Host @Ext (Sock)) (Obj)
    419                (when (or Sock (setq Sock (connect @Host 4040)))
    420                   (ext @Ext
    421                      (out Sock (pr (cons 'qsym Obj)))
    422                      (prog1 (in Sock (rd))
    423                         (unless @
    424                            (close Sock)
    425                            (off Sock) ) ) ) ) ) ) )
    426       '("localhost")
    427       '(20) ) )
    428 
    429 (de rsrc ()  # Simple resource handler, ignoring errors or EOFs
    430    (extract
    431       '((@Ext Host)
    432          (let? @Sock (connect Host 4040)
    433             (cons
    434                (curry (@Ext @Sock) (X)  # out
    435                   (ext @Ext (out @Sock (pr X))) )
    436                (curry (@Ext @Sock) ()  # in
    437                   (ext @Ext (in @Sock (rd))) ) ) ) )
    438       '(20)
    439       '("localhost") ) )
    440 
    441 : (?
    442    @Nr (1 . 3)
    443    @Sup 2
    444    @Rsrc (rsrc)
    445    (remote (@Item . @Rsrc)
    446       (db nr +Item @Nr @Item)
    447       (val @Sup @Item sup nr) )
    448    (show @Item) )
    449 {L-2} (+Item)
    450    pr 1250
    451    inv 100
    452    sup {K-2}
    453    nm Spare Part
    454    nr 2
    455  @Nr=(1 . 3) @Sup=2 @Rsrc=((((X) (ext 20 (out 16 (pr X)))) NIL (ext 20 (in 16 (rd))))) @Item={L-2}
    456 -> NIL
    457 </code></pre>
    458 
    459 <dt><a name="remove"><code>(remove 'cnt 'lst) -> lst</code></a>
    460 <dd>Removes the element at position <code>cnt</code> from <code>lst</code>. This
    461 is a non-destructive operation. See also <code><a
    462 href="refI.html#insert">insert</a></code>, <code><a
    463 href="refP.html#place">place</a></code>, <code><a
    464 href="refA.html#append">append</a></code>, <code><a
    465 href="refD.html#delete">delete</a></code> and <code><a
    466 href="refR.html#replace">replace</a></code>.
    467 
    468 <pre><code>
    469 : (remove 3 '(a b c d e))
    470 -> (a b d e)
    471 : (remove 1 '(a b c d e))
    472 -> (b c d e)
    473 : (remove 9 '(a b c d e))
    474 -> (a b c d e)
    475 </code></pre>
    476 
    477 <dt><a name="repeat"><code>(repeat) -> lst</code></a>
    478 <dd>Makes the current <a href="ref.html#pilog">Pilog</a> definition "tail
    479 recursive", by closing the previously defined rules in the definition's T
    480 property to a circular list. See also <code><a
    481 href="refR.html#repeat/0">repeat/0</a></code> and <code><a
    482 href="refB.html#be">be</a></code>.
    483 
    484 <pre><code>
    485 (be a (1))     # Define three facts
    486 (be a (2))
    487 (be a (3))
    488 (repeat)       # Unlimited supply
    489 
    490 : (? (a @N))
    491  @N=1
    492  @N=2
    493  @N=3
    494  @N=1
    495  @N=2
    496  @N=3.         # Stop
    497 -> NIL
    498 </code></pre>
    499 
    500 <dt><a name="repeat/0"><code>repeat/0</code></a>
    501 <dd><a href="ref.html#pilog">Pilog</a> predicate that always succeeds, also on
    502 backtracking. See also <code><a href="refR.html#repeat">repeat</a></code> and
    503 <code><a href="refT.html#true/0">true/0</a></code>.
    504 
    505 <pre><code>
    506 : (be integer (@I)   # Generate unlimited supply of integers
    507    (^ @C (box 0))    # Init to zero
    508    (repeat)          # Repeat from here
    509    (^ @I (inc (-> @C))) )
    510 -> integer
    511 
    512 : (? (integer @X))
    513  @X=1
    514  @X=2
    515  @X=3
    516  @X=4.               # Stop
    517 -> NIL
    518 </code></pre>
    519 
    520 <dt><a name="replace"><code>(replace 'lst 'any1 'any2 ..) -> lst</code></a>
    521 <dd>Replaces in <code>lst</code> all occurrences of <code>any1</code> with
    522 <code>any2</code>. For optional additional argument pairs, this process is
    523 repeated. This is a non-destructive operation. See also <code><a
    524 href="refA.html#append">append</a></code>, <code><a
    525 href="refD.html#delete">delete</a></code>, <code><a
    526 href="refI.html#insert">insert</a></code>, <code><a
    527 href="refR.html#remove">remove</a></code> and <code><a
    528 href="refP.html#place">place</a></code>.
    529 
    530 <pre><code>
    531 : (replace '(a b b a) 'a 'A)
    532 -> (A b b A)
    533 : (replace '(a b b a) 'b 'B)
    534 -> (a B B a)
    535 : (replace '(a b b a) 'a 'B 'b 'A)
    536 -> (B A A B)
    537 </code></pre>
    538 
    539 <dt><a name="request"><code>(request 'typ 'var ['hook] 'val ..) -> obj</code></a>
    540 <dd>Returns a database object. If a matching object cannot be found (using
    541 <code><a href="refD.html#db">db</a></code>), a new object of the given type is
    542 created (using <code><a href="refN.html#new">new</a></code>). See also <code><a
    543 href="refO.html#obj">obj</a></code>.
    544 
    545 <pre><code>
    546 : (request '(+Item) 'nr 2)
    547 -> {3-2}
    548 </code></pre>
    549 
    550 <dt><a name="rest"><code>(rest) -> lst</code></a>
    551 <dd>Can only be used inside functions with a variable number of arguments (with
    552 <code>@</code>). Returns the list of all remaining arguments from the internal
    553 list. See also <code><a href="refA.html#args">args</a></code>, <code><a
    554 href="refN.html#next">next</a></code>, <code><a
    555 href="refA.html#arg">arg</a></code> and <code><a
    556 href="refP.html#pass">pass</a></code>.
    557 
    558 <pre><code>
    559 : (de foo @ (println (rest)))
    560 -> foo
    561 : (foo 1 2 3)
    562 (1 2 3)
    563 -> (1 2 3)
    564 </code></pre>
    565 
    566 <dt><a name="retract"><code>(retract) -> lst</code></a>
    567 <dd>Removes a <a href="ref.html#pilog">Pilog</a> fact or rule. See also <code><a
    568 href="refB.html#be">be</a></code>, <code><a
    569 href="refC.html#clause">clause</a></code>, <code><a
    570 href="refA.html#asserta">asserta</a></code> and <code><a
    571 href="refA.html#assertz">assertz</a></code>.
    572 
    573 <pre><code>
    574 : (be a (1))
    575 -> a
    576 : (be a (2))
    577 -> a
    578 : (be a (3))
    579 -> a
    580 
    581 : (retract '(a (2)))
    582 -> (((1)) ((3)))
    583 
    584 :  (? (a @N))
    585  @N=1
    586  @N=3
    587 -> NIL
    588 </code></pre>
    589 
    590 <dt><a name="retract/1"><code>retract/1</code></a>
    591 <dd><a href="ref.html#pilog">Pilog</a> predicate that removes a fact or rule.
    592 See also <code><a href="refR.html#retract">retract</a></code>, <code><a
    593 href="refA.html#asserta/1">asserta/1</a></code> and <code><a
    594 href="refA.html#assertz/1">assertz/1</a></code>.
    595 
    596 <pre><code>
    597 : (be a (1))
    598 -> a
    599 : (be a (2))
    600 -> a
    601 : (be a (3))
    602 -> a
    603 
    604 : (? (retract (a 2)))
    605 -> T
    606 : (rules 'a)
    607 1 (be a (1))
    608 2 (be a (3))
    609 -> a
    610 </code></pre>
    611 
    612 <dt><a name="reverse"><code>(reverse 'lst) -> lst</code></a>
    613 <dd>Returns a reversed copy of <code>lst</code>. See also <code><a
    614 href="refF.html#flip">flip</a></code>.
    615 
    616 <pre><code>
    617 : (reverse (1 2 3 4))
    618 -> (4 3 2 1)
    619 </code></pre>
    620 
    621 <dt><a name="rewind"><code>(rewind) -> flg</code></a>
    622 <dd>Sets the file position indicator for the current output stream to the
    623 beginning of the file, and truncates the file length to zero. Returns
    624 <code>T</code> when successful. See also <code><a
    625 href="refF.html#flush">flush</a></code>.
    626 
    627 <pre><code>
    628 : (out "a" (prinl "Hello world"))
    629 -> "Hello world"
    630 : (in "a" (echo))
    631 Hello world
    632 -> T
    633 : (info "a")
    634 -> (12 733216 . 53888)
    635 : (out "a" (rewind))
    636 -> T
    637 : (info "a")
    638 -> (0 733216 . 53922)
    639 </code></pre>
    640 
    641 <dt><a name="rollback"><code>(rollback) -> T</code></a>
    642 <dd>Cancels a transaction, by discarding all modifications of external symbols.
    643 See also <code><a href="refC.html#commit">commit</a></code>.
    644 
    645 <pre><code>
    646 : (pool "db")
    647 -> T
    648 # .. Modify external objects ..
    649 : (rollback)            # Rollback
    650 -> T
    651 </code></pre>
    652 
    653 <dt><a name="root"><code>(root 'tree) -> (num . sym)</code></a>
    654 <dd>Returns the root of a database index tree, with the number of entries in
    655 <code>num</code>, and the base node in <code>sym</code>. See also <code><a
    656 href="refT.html#tree">tree</a></code>.
    657 
    658 <pre><code>
    659 : (root (tree 'nr '+Item))
    660 -> (7 . {7-1})
    661 </code></pre>
    662 
    663 <dt><a name="rot"><code>(rot 'lst ['cnt]) -> lst</code></a>
    664 <dd>Rotate: The contents of the cells of <code>lst</code> are (destructively)
    665 shifted right, and the value from the last cell is stored in the first cell.
    666 Without the optional <code>cnt</code> argument, the whole list is rotated,
    667 otherwise only the first <code>cnt</code> elements. See also <code><a
    668 href="refF.html#flip">flip</a></code> .
    669 
    670 <pre><code>
    671 : (rot (1 2 3 4))             # Rotate all four elements
    672 -> (4 1 2 3)
    673 : (rot (1 2 3 4 5 6) 3)       # Rotate only the first three elements
    674 -> (3 1 2 4 5 6)
    675 </code></pre>
    676 
    677 <dt><a name="round"><code>(round 'num1 'num2) -> sym</code></a>
    678 <dd>Formats a number <code>num1</code> with <code>num2</code> decimal places,
    679 according to the current scale <code><a href="refS.html#*Scl">*Scl</a></code>.
    680 <code>num2</code> defaults to 3. See also <a href="ref.html#num-io">Numbers</a>
    681 and <code><a href="refF.html#format">format</a></code>.
    682 
    683 <pre><code>
    684 : (scl 4)               # Set scale to 4
    685 -> 4
    686 : (round 123456)        # Format with three decimal places
    687 -> "12.346"
    688 : (round 123456 2)      # Format with two decimal places
    689 -> "12.35"
    690 : (format 123456 *Scl)  # Format with full precision
    691 -> "12.3456"
    692 </code></pre>
    693 
    694 <dt><a name="rules"><code>(rules 'sym ..) -> sym</code></a>
    695 <dd>Prints all rules defined for the <code>sym</code> arguments. See also <a
    696 href="ref.html#pilog">Pilog</a> and <code><a href="refB.html#be">be</a></code>.
    697 
    698 <pre><code>
    699 : (rules 'member 'append)
    700 1 (be member (@X (@X . @)))
    701 2 (be member (@X (@ . @Y)) (member @X @Y))
    702 1 (be append (NIL @X @X))
    703 2 (be append ((@A . @X) @Y (@A . @Z)) (append @X @Y @Z))
    704 -> append
    705 </code></pre>
    706 
    707 <dt><a name="run"><code>(run 'any ['cnt ['lst]]) -> any</code></a>
    708 <dd>If <code>any</code> is an atom, <code>run</code> behaves like <code><a
    709 href="refE.html#eval">eval</a></code>. Otherwise <code>any</code> is a list,
    710 which is evaluated in sequence. The last result is returned. If a binding
    711 environment offset <code>cnt</code> is given, that evaluation takes place in the
    712 corresponding environment, and an optional <code>lst</code> of excluded symbols
    713 can be supplied. See also <code><a href="refU.html#up">up</a></code>.
    714 
    715 <pre><code>
    716 : (run '((println (+ 1 2 3)) (println 'OK)))
    717 6
    718 OK
    719 -> OK
    720 </code></pre>
    721 
    722 </dl>
    723 
    724 </body>
    725 </html>