refF.html (19160B)
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>F</title> 6 <link rel="stylesheet" href="doc.css" type="text/css"> 7 </head> 8 <body> 9 10 <h1>F</h1> 11 12 <dl> 13 14 <dt><a name="*Fork"><code>*Fork</code></a> 15 <dd>A global variable holding a (possibly empty) <code>prg</code> body, to be 16 executed after a call to <code><a href="refF.html#fork">fork</a></code> in the 17 child process. 18 19 <pre><code> 20 : (push '*Fork '(off *Tmp)) # Clear '*Tmp' in child process 21 -> (off *Tmp) 22 </code></pre> 23 24 <dt><a name="+Fold"><code>+Fold</code></a> 25 <dd>Prefix class for maintaining <code><a 26 href="refF.html#fold">fold</a></code>ed indexes to <code><a 27 href="refS.html#+String">+String</a></code> relations. Typically used in 28 combination with the <code><a href="refR.html#+Ref">+Ref</a></code> or <code><a 29 href="refI.html#+Idx">+Idx</a></code> prefix classes. See also <code><a 30 href="refI.html#+IdxFold">+IdxFold</a></code> and <a 31 href="ref.html#dbase">Database</a>. 32 33 <pre><code> 34 (rel nm (+Fold +Idx +String)) # Item Description 35 ... 36 (rel tel (+Fold +Ref +String)) # Phone number 37 </code></pre> 38 39 <dt><a name="fail"><code>(fail) -> lst</code></a> 40 <dd>Constructs an empty <a href="ref.html#pilog">Pilog</a> query, i.e. a query 41 that will aways fail. See also <code><a href="refG.html#goal">goal</a></code>. 42 43 <pre><code> 44 (dm clr> () # Clear query chart in search dialogs 45 (query> This (fail)) ) 46 </code></pre> 47 48 <dt><a name="fail/0"><code>fail/0</code></a> 49 <dd><a href="ref.html#pilog">Pilog</a> predicate that always fails. See also 50 <code><a href="refT.html#true/0">true/0</a></code>. 51 52 <pre><code> 53 : (? (fail)) 54 -> NIL 55 </code></pre> 56 57 <dt><a name="fetch"><code>(fetch 'tree 'any) -> any</code></a> 58 <dd>Fetches a value for the key <code>any</code> from a database tree. See also 59 <code><a href="refT.html#tree">tree</a></code> and <code><a 60 href="refS.html#store">store</a></code>. 61 62 <pre><code> 63 : (fetch (tree 'nr '+Item) 2) 64 -> {3-2} 65 </code></pre> 66 67 <dt><a name="fifo"><code>(fifo 'var ['any ..]) -> any</code></a> 68 <dd>Implements a first-in-first-out structure using a circular list. When called 69 with <code>any</code> arguments, they will be concatenated to end of the 70 structure. Otherwise, the first element is removed from the structure and 71 returned. See also <code><a href="refQ.html#queue">queue</a></code>, <code><a 72 href="refP.html#push">push</a></code>, <code><a 73 href="refP.html#pop">pop</a></code>, <code><a 74 href="refR.html#rot">rot</a></code> and <code><a 75 href="refC.html#circ">circ</a></code>. 76 77 <pre><code> 78 : (fifo 'X 1) 79 -> 1 80 : (fifo 'X 2 3) 81 -> 3 82 : X 83 -> (3 1 2 .) 84 : (fifo 'X) 85 -> 1 86 : (fifo 'X) 87 -> 2 88 : X 89 -> (3 .) 90 </code></pre> 91 92 <dt><a name="file"><code>(file) -> (sym1 sym2 . num) | NIL</code></a> 93 <dd>Returns for the current input channel the path name <code>sym1</code>, the 94 file name <code>sym2</code>, and the current line number <code>num</code>. If 95 the current input channel is not a file, <code>NIL</code> is returned. See also 96 <code><a href="refI.html#info">info</a></code>, <code><a 97 href="refI.html#in">in</a></code> and <code><a 98 href="refL.html#load">load</a></code>. 99 100 <pre><code> 101 : (load (pack (car (file)) "localFile.l")) # Load a file in same directory 102 </code></pre> 103 104 <dt><a name="fill"><code>(fill 'any ['sym|lst]) -> any</code></a> 105 <dd>Non-destructively fills a pattern <code>any</code>, by substituting 106 <code>sym</code>, or all symbols in <code>lst</code>, or - if no second argument 107 is given - each pattern symbol in <code>any</code> (see <code><a 108 href="refP.html#pat?">pat?</a></code>), with its current value. <code>@</code> 109 itself is not considered a pattern symbol here. Unmodified subexpressions are 110 shared. In any case, expressions following the symbol <code>^</code> should 111 evaluate to lists which are then (destructively) spliced into the result. See 112 also <code><a href="refM.html#match">match</a></code>. 113 114 <pre><code> 115 : (setq @X 1234 @Y (1 2 3 4)) 116 -> (1 2 3 4) 117 : (fill '@X) 118 -> 1234 119 : (fill '(a b (c @X) ((@Y . d) e))) 120 -> (a b (c 1234) (((1 2 3 4) . d) e)) 121 : (let X 2 (fill (1 X 3) 'X)) 122 -> (1 2 3) 123 124 : (fill (1 ^ (list 'a 'b 'c) 9)) 125 -> (1 a b c 9) 126 127 : (match '(This is @X) '(This is a pen)) 128 -> T 129 : (fill '(Got ^ @X)) 130 -> (Got a pen) 131 </code></pre> 132 133 <dt><a name="filter"><code>(filter 'fun 'lst ..) -> lst</code></a> 134 <dd>Applies <code>fun</code> to each element of <code>lst</code>. When 135 additional <code>lst</code> arguments are given, their elements are also passed 136 to <code>fun</code>. Returns a list of all elements of <code>lst</code> where 137 <code>fun</code> returned non-<code>NIL</code>. See also <code><a 138 href="refF.html#fish">fish</a></code>, <code><a 139 href="refF.html#find">find</a></code>, <code><a 140 href="refP.html#pick">pick</a></code> and <code><a 141 href="refE.html#extract">extract</a></code>. 142 143 <pre><code> 144 : (filter num? (1 A 2 (B) 3 CDE)) 145 -> (1 2 3) 146 </code></pre> 147 148 <dt><a name="fin"><code>(fin 'any) -> num|sym</code></a> 149 <dd>Returns <code>any</code> if it is an atom, otherwise the CDR of its last 150 cell. See also <code><a href="refL.html#last">last</a></code> and <code><a 151 href="refT.html#tail">tail</a></code>. 152 153 <pre><code> 154 : (fin 'a) 155 -> a 156 : (fin '(a . b)) 157 -> b 158 : (fin '(a b . c)) 159 -> c 160 : (fin '(a b c)) 161 -> NIL 162 </code></pre> 163 164 <dt><a name="finally"><code>(finally exe . prg) -> any</code></a> 165 <dd><code>prg</code> is executed, then <code>exe</code> is evaluated, and the 166 result of <code>prg</code> is returned. <code>exe</code> will also be evaluated 167 if <code>prg</code> does not terminate normally due to a runtime error or a call 168 to <code><a href="refT.html#throw">throw</a></code>. See also <code><a 169 href="refB.html#bye">bye</a></code>, <code><a 170 href="refC.html#catch">catch</a></code>, <code><a 171 href="refQ.html#quit">quit</a></code> and <code><a href="ref.html#errors">Error 172 Handling</a></code>. 173 174 <pre><code> 175 : (finally (prinl "Done!") 176 (println 123) 177 (quit) 178 (println 456) ) 179 123 180 Done! 181 : (catch 'A 182 (finally (prinl "Done!") 183 (println 1) 184 (throw 'A 123) 185 (println 2) ) ) 186 1 187 Done! 188 -> 123 189 </code></pre> 190 191 <dt><a name="find"><code>(find 'fun 'lst ..) -> any</code></a> 192 <dd>Applies <code>fun</code> to successive elements of <code>lst</code> until 193 non-<code>NIL</code> is returned. Returns that element, or <code>NIL</code> if 194 <code>fun</code> did not return non-<code>NIL</code> for any element of 195 <code>lst</code>. When additional <code>lst</code> arguments are given, their 196 elements are also passed to <code>fun</code>. See also <code><a 197 href="refS.html#seek">seek</a></code>, <code><a 198 href="refP.html#pick">pick</a></code> and <code><a 199 href="refF.html#filter">filter</a></code>. 200 201 <pre><code> 202 : (find pair (1 A 2 (B) 3 CDE)) 203 -> (B) 204 : (find '((A B) (> A B)) (1 2 3 4 5 6) (6 5 4 3 2 1)) 205 -> 4 206 : (find > (1 2 3 4 5 6) (6 5 4 3 2 1)) # shorter 207 -> 4 208 </code></pre> 209 210 <dt><a name="fish"><code>(fish 'fun 'any) -> lst</code></a> 211 <dd>Applies <code>fun</code> to each element - and recursively to all sublists - 212 of <code>any</code>. Returns a list of all items where <code>fun</code> returned 213 non-<code>NIL</code>. See also <code><a 214 href="refF.html#filter">filter</a></code>. 215 216 <pre><code> 217 : (fish gt0 '(a -2 (1 b (-3 c 2)) 3 d -1)) 218 -> (1 2 3) 219 : (fish sym? '(a -2 (1 b (-3 c 2)) 3 d -1)) 220 -> (a b c d) 221 </code></pre> 222 223 <dt><a name="flg?"><code>(flg? 'any) -> flg</code></a> 224 <dd>Returns <code>T</code> when the argument <code>any</code> is either 225 <code>NIL</code> or <code>T</code>. See also <code><a 226 href="refB.html#bool">bool</a></code>. <code>(flg? X)</code> is equivalent to 227 <code>(or (not X) (=T X))</code>. 228 229 <pre><code> 230 : (flg? (= 3 3)) 231 -> T 232 : (flg? (= 3 4)) 233 -> T 234 : (flg? (+ 3 4)) 235 -> NIL 236 </code></pre> 237 238 <dt><a name="flip"><code>(flip 'lst ['cnt]) -> lst</code></a> 239 <dd>Returns <code>lst</code> (destructively) reversed. Without the optional 240 <code>cnt</code> argument, the whole list is flipped, otherwise only the first 241 <code>cnt</code> elements. See also <code><a 242 href="refR.html#reverse">reverse</a></code> and <code><a 243 href="refR.html#rot">rot</a></code>. 244 245 <pre><code> 246 : (flip (1 2 3 4)) # Flip all four elements 247 -> (4 3 2 1) 248 : (flip (1 2 3 4 5 6) 3) # Flip only the first three elements 249 -> (3 2 1 4 5 6) 250 </code></pre> 251 252 <dt><a name="flush"><code>(flush) -> flg</code></a> 253 <dd>Flushes the current output stream by writing all buffered data. A call to 254 <code>flush</code> for standard output is done automatically before a call to 255 <code><a href="refK.html#key">key</a></code>. Returns <code>T</code> when 256 successful. See also <code><a href="refR.html#rewind">rewind</a></code>. 257 258 <pre><code> 259 : (flush) 260 -> T 261 </code></pre> 262 263 <dt><a name="fmt64"><code>(fmt64 'num) -> sym</code></a> 264 <dt><code>(fmt64 'sym) -> num</code> 265 <dd>Converts a number <code>num</code> to a string in base-64 notation, or a 266 base-64 formatted string to a number. The digits are represented with the 267 characters <code>0</code> - <code>9</code>, <code>:</code>, <code>;</code>, 268 <code>A</code> - <code>Z</code> and <code>a</code> - <code>z</code>. This format 269 is used internally for the names of <code><a 270 href="ref.html#external-io">external symbols</a></code> in the 32-bit version. 271 See also <code><a href="refH.html#hax">hax</a></code>, <code><a 272 href="refH.html#hex">hex</a></code>, <code><a 273 href="refB.html#bin">bin</a></code> and <code><a 274 href="refO.html#oct">oct</a></code>. 275 276 <pre><code> 277 : (fmt64 9) 278 -> "9" 279 : (fmt64 10) 280 -> ":" 281 : (fmt64 11) 282 -> ";" 283 : (fmt64 12) 284 -> "A" 285 : (fmt64 "100") 286 -> 4096 287 </code></pre> 288 289 <dt><a name="fold"><code>(fold 'any ['cnt]) -> sym</code></a> 290 <dd>Folding to a canonical form: If <code>any</code> is not a symbol, it is 291 returned as it is. Otherwise, a new transient symbol with all digits and all 292 letters of <code>any</code>, converted to lower case, is returned. If the 293 <code>cnt</code> argument is given and non-zero, the result is truncated to that 294 length. See also <code><a href="refL.html#lowc">lowc</a></code>. 295 296 <pre><code> 297 : (fold " 1A 2-b/3") 298 -> "1a2b3" 299 : (fold " 1A 2-B/3" 3) 300 -> "1a2" 301 </code></pre> 302 303 <dt><a name="fold/3"><code>fold/3</code></a> 304 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the first 305 argument, after <code><a href="refF.html#fold">fold</a></code>ing it to a 306 canonical form, is a <i>prefix</i> of the folded string representation of the 307 result of applying the <code><a href="refG.html#get">get</a></code> algorithm to 308 the following arguments. Typically used as filter predicate in <code><a 309 href="refS.html#select/3">select/3</a></code> database queries. See also 310 <code><a href="refP.html#pre?">pre?</a></code>, <code><a 311 href="refI.html#isa/2">isa/2</a></code>, <code><a 312 href="refS.html#same/3">same/3</a></code>, <code><a 313 href="refB.html#bool/3">bool/3</a></code>, <code><a 314 href="refR.html#range/3">range/3</a></code>, <code><a 315 href="refH.html#head/3">head/3</a></code>, <code><a 316 href="refP.html#part/3">part/3</a></code> and <code><a 317 href="refT.html#tolr/3">tolr/3</a></code>. 318 319 <pre><code> 320 : (? 321 @Nr (1 . 5) 322 @Nm "main" 323 (select (@Item) 324 ((nr +Item @Nr) (nm +Item @Nm)) 325 (range @Nr @Item nr) 326 (fold @Nm @Item nm) ) ) 327 @Nr=(1 . 5) @Nm="main" @Item={3-1} 328 -> NIL 329 </code></pre> 330 331 <dt><a name="for"><code>(for sym 'num ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any</code></a> 332 <dt><code>(for sym|(sym2 . sym) 'lst ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any</code> 333 <dt><code>(for (sym|(sym2 . sym) 'any1 'any2 [. prg]) ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any</code> 334 <dd>Conditional loop with local variable(s) and multiple conditional exits:<br> 335 In the first form, the value of <code>sym</code> is saved, <code>sym</code> is 336 bound to <code>1</code>, and the body is executed with increasing values up to 337 (and including) <code>num</code>.<br> 338 339 In the second form, the value of <code>sym</code> is saved, <code>sym</code> is 340 subsequently bound to the elements of <code>lst</code>, and the body is executed 341 each time.<br> 342 343 In the third form, the value of <code>sym</code> is saved, and <code>sym</code> 344 is bound to <code>any1</code>. If <code>sym2</code> is given, it is treated as a 345 counter variable, first bound to 1 and then incremented for each execution of 346 the body. While the condition <code>any2</code> evaluates to 347 non-<code>NIL</code>, the body is repeatedly executed and, if <code>prg</code> 348 is given, <code>sym</code> is re-bound to the result of its evaluation.<br> 349 350 If a clause has <code>NIL</code> or <code>T</code> as its CAR, the clause's 351 second element is evaluated as a condition and - if the result is 352 <code>NIL</code> or non-<code>NIL</code>, respectively - the <code>prg</code> is 353 executed and the result returned. If the body is never executed, 354 <code>NIL</code> is returned.<br> 355 356 See also <code><a href="refD.html#do">do</a></code> and <code><a 357 href="refL.html#loop">loop</a></code>. 358 359 <pre><code> 360 # First form: 361 : (for N 5 (printsp N)) 362 1 2 3 4 5 -> 5 363 : (for N 5 (printsp N) (NIL (< N 3) (printsp 'enough))) 364 1 2 3 enough -> enough 365 : (for N 5 (T (> N 3) (printsp 'enough)) (printsp N)) 366 1 2 3 enough -> enough 367 368 # Second form: 369 : (for X (1 a 2 b) (printsp X)) 370 1 a 2 b -> b 371 : (for (I . X) '(a b c) (println I X)) 372 1 a 373 2 b 374 3 c 375 -> c 376 377 # Third form: 378 : (for (L (1 2 3 4 5) L) (printsp (pop 'L))) 379 1 2 3 4 5 -> 5 380 : (for (N 1 (>= 5 N) (inc N)) (printsp N)) 381 1 2 3 4 5 -> 5 382 : (for ((I . L) '(a b c d e f) L (cddr L)) (println I L)) 383 1 (a b c d e f) 384 2 (c d e f) 385 3 (e f) 386 -> (e f) 387 </code></pre> 388 389 <dt><a name="for/2"><code>for/2</code></a> 390 <dt><a name="for/3"><code>for/3</code></a> 391 <dt><a name="for/4"><code>for/4</code></a> 392 <dd><a href="ref.html#pilog">Pilog</a> predicate that generates a sequence of 393 numbers. See also <code><a href="refF.html#for">for</a></code> and <code><a 394 href="refR.html#range">range</a></code>. 395 396 <pre><code> 397 : (? (for @I 3)) 398 @I=1 399 @I=2 400 @I=3 401 -> NIL 402 403 : (? (for @I 3 7)) 404 @I=3 405 @I=4 406 @I=5 407 @I=6 408 @I=7 409 -> NIL 410 411 : (? (for @I 7 3 2)) 412 @I=7 413 @I=5 414 @I=3 415 -> NIL 416 </code></pre> 417 418 <dt><a name="fork"><code>(fork) -> pid | NIL</code></a> 419 <dd>Forks a child process. Returns <code>NIL</code> in the child, and the 420 child's process ID <code>pid</code> in the parent. In the child, the 421 <code>VAL</code> of the global variable <code><a 422 href="refF.html#*Fork">*Fork</a></code> (should be a <code>prg</code>) is 423 executed. See also <code><a href="refP.html#pipe">pipe</a></code> and <code><a 424 href="refT.html#tell">tell</a></code>. 425 426 <pre><code> 427 : (unless (fork) (do 5 (println 'OK) (wait 1000)) (bye)) 428 -> NIL 429 OK # Child's output 430 : OK 431 OK 432 OK 433 OK 434 </code></pre> 435 436 <dt><a name="forked"><code>(forked)</code></a> 437 <dd>Installs maintenance code in <code><a 438 href="refF.html#*Fork">*Fork</a></code> to close server sockets and clean up 439 <code><a href="refR.html#*Run">*Run</a></code> code in child processes. Should 440 only be called immediately after <code><a href="refT.html#task">task</a></code>. 441 442 <pre><code> 443 : (task -60000 60000 (msg 'OK)) # Install timer task 444 -> (-60000 60000 (msg 'OK)) 445 : (forked) # No timer in child processes 446 -> (task -60000) 447 : *Run 448 -> ((-60000 56432 (msg 'OK))) 449 : *Fork 450 -> ((task -60000) (del '(saveHistory) '*Bye)) 451 </code></pre> 452 453 <dt><a name="format"><code>(format 'num ['cnt ['sym1 ['sym2]]]) -> sym</code></a> 454 <dt><code>(format 'sym|lst ['cnt ['sym1 ['sym2]]]) -> num</code> 455 <dd>Converts a number <code>num</code> to a string, or a string 456 <code>sym|lst</code> to a number. In both cases, optionally a precision 457 <code>cnt</code>, a decimal-separator <code>sym1</code> and a 458 thousands-separator <code>sym2</code> can be supplied. Returns <code>NIL</code> 459 if the conversion is unsuccessful. See also <a 460 href="ref.html#num-io">Numbers</a> and <code><a 461 href="refR.html#round">round</a></code>. 462 463 <pre><code> 464 : (format 123456789) # Integer conversion 465 -> "123456789" 466 : (format 123456789 2) # Fixed point 467 -> "1234567.89" 468 : (format 123456789 2 ",") # Comma as decimal-separator 469 -> "1234567,89" 470 : (format 123456789 2 "," ".") # and period as thousands-separator 471 -> "1.234.567,89" 472 473 : (format "123456789") # String to number 474 -> 123456789 475 : (format (1 "23" (4 5 6))) 476 -> 123456 477 : (format "1234567.89" 4) # scaled to four digits 478 -> 12345678900 479 : (format "1.234.567,89") # separators not recognized 480 -> NIL 481 : (format "1234567,89" 4 ",") 482 -> 12345678900 483 : (format "1.234.567,89" 4 ",") # thousands-separator not recognized 484 -> NIL 485 : (format "1.234.567,89" 4 "," ".") 486 -> 12345678900 487 </code></pre> 488 489 <dt><a name="free"><code>(free 'cnt) -> (sym . lst)</code></a> 490 <dd>Returns, for the <code>cnt</code>'th database file, the next available 491 symbol <code>sym</code> (i.e. the first symbol greater than any symbol in the 492 database), and the list <code>lst</code> of free symbols. See also <code><a 493 href="refS.html#seq">seq</a></code>, <code><a 494 href="refZ.html#zap">zap</a></code> and <code><a 495 href="refD.html#dbck">dbck</a></code>. 496 497 <pre><code> 498 : (pool "x") # A new database 499 -> T 500 : (new T) # Create a new symbol 501 -> {2} 502 : (new T) # Create another symbol 503 -> {3} 504 : (commit) # Commit changes 505 -> T 506 : (zap '{2}) # Delete the first symbol 507 -> {2} 508 : (free 1) # Show free list 509 -> ({4}) # {3} was the last symbol allocated 510 : (commit) # Commit the deletion of {2} 511 -> T 512 : (free 1) # Now {2} is in the free list 513 -> ({4} {2}) 514 </code></pre> 515 516 <dt><a name="from"><code>(from 'any ..) -> sym</code></a> 517 <dd>Skips the current input channel until one of the strings <code>any</code> is 518 found, and starts subsequent reading from that point. The found <code>any</code> 519 argument, or <code>NIL</code> (if none is found) is returned. See also <code><a 520 href="refT.html#till">till</a></code> and <code><a 521 href="refE.html#echo">echo</a></code>. 522 523 <pre><code> 524 : (and (from "val='") (till "'" T)) 525 test val='abc' 526 -> "abc" 527 </code></pre> 528 529 <dt><a name="full"><code>(full 'any) -> bool</code></a> 530 <dd>Returns <code>NIL</code> if <code>any</code> is a non-empty list with at 531 least one <code>NIL</code> element, otherwise <code>T</code>. <code>(full 532 X)</code> is equivalent to <code>(not (memq NIL X))</code>. 533 534 <pre><code> 535 : (full (1 2 3)) 536 -> T 537 : (full (1 NIL 3)) 538 -> NIL 539 : (full 123) 540 -> T 541 </code></pre> 542 543 <dt><a name="fun?"><code>(fun? 'any) -> any</code></a> 544 <dd>Returns <code>NIL</code> when the argument <code>any</code> is neither a 545 number suitable for a code-pointer, nor a list suitable for a lambda expression 546 (function). Otherwise a number is returned for a code-pointer, <code>T</code> 547 for a function without arguments, and a single formal parameter or a list of 548 formal parameters for a function. See also <code><a 549 href="refG.html#getd">getd</a></code>. 550 551 <pre><code> 552 : (fun? 1000000000) # Might be a code pointer 553 -> 1000000000 554 : (fun? 100000000000000) # Too big for a code pointer 555 -> NIL 556 : (fun? 1000000001) # Cannot be a code pointer (odd) 557 -> NIL 558 : (fun? '((A B) (* A B))) # Lambda expression 559 -> (A B) 560 : (fun? '((A B) (* A B) . C)) # Not a lambda expression 561 -> NIL 562 : (fun? '(1 2 3 4)) # Not a lambda expression 563 -> NIL 564 : (fun? '((A 2 B) (* A B))) # Not a lambda expression 565 -> NIL 566 </code></pre> 567 568 </dl> 569 570 </body> 571 </html>