1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>C</title>
<link rel="stylesheet" href="doc.css" type="text/css">
</head>
<body>
<h1>C</h1>
<dl>
<dt><a name="*Class"><code>*Class</code></a>
<dd>A global variable holding the current class. See also <code><a
href="ref.html#oop">OO Concepts</a></code>, <code><a
href="refC.html#class">class</a></code>, <code><a
href="refE.html#extend">extend</a></code>, <code><a
href="refD.html#dm">dm</a></code> and <code><a
href="refV.html#var">var</a></code> and <code><a
href="refR.html#rel">rel</a></code>.
<pre><code>
: (class +Test)
-> +Test
: *Class
-> +Test
</code></pre>
<dt><a name="cache"><code>(cache 'var 'sym . prg) -> any</code></a>
<dd>Speeds up some calculations, by holding previously calculated results in an
<code><a href="refI.html#idx">idx</a></code> tree structure. Such an
optimization is sometimes called "memoization". <code>sym</code> must be a
transient symbol representing a unique key for the argument(s) to the
calculation. See also <code><a href="refH.html#hash">hash</a></code>.
<pre><code>
: (de fibonacci (N)
(cache '(NIL) (pack (char (hash N)) N)
(if (> 2 N)
1
(+
(fibonacci (dec N))
(fibonacci (- N 2)) ) ) ) )
-> fibonacci
: (fibonacci 22)
-> 28657
: (fibonacci 10000)
-> 5443837311356528133873426099375038013538 ... # (2090 digits)
</code></pre>
<dt><a name="call"><code>(call 'any ..) -> flg</code></a>
<dd>Calls an external system command. The <code>any</code> arguments specify the
command and its arguments. Returns <code>T</code> if the command was executed
successfully.
<pre><code>
: (when (call 'test "-r" "file.l") # Test if file exists and is readable
(load "file.l") # Load it
(call 'rm "file.l") ) # Remove it
</code></pre>
<dt><a name="call/1"><code>call/1</code></a>
<dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the argument
term can be proven.
<pre><code>
: (be mapcar (@ NIL NIL))
-> mapcar
: (be mapcar (@P (@X . @L) (@Y . @M))
(call @P @X @Y) # Call the given predicate
(mapcar @P @L @M) )
-> mapcar
: (? (mapcar change (you are a computer) @Z))
-> NIL
: (? (mapcar change (you are a computer) @Z) T)
-> NIL
: (? (mapcar permute ((a b c) (d e f)) @X))
@X=((a b c) (d e f))
@X=((a b c) (d f e))
@X=((a b c) (e d f))
...
@X=((a c b) (d e f))
@X=((a c b) (d f e))
@X=((a c b) (e d f))
...
</code></pre>
<dt><a name="can"><code>(can 'msg) -> lst</code></a>
<dd>Returns a list of all classes that accept the message <code>msg</code>. See
also <code><a href="ref.html#oop">OO Concepts</a></code>, <code><a
href="refC.html#class">class</a></code>, <code><a
href="refD.html#dep">dep</a></code>, <code><a
href="refW.html#what">what</a></code> and <code><a
href="refW.html#who">who</a></code>.
<pre><code>
: (can 'zap>)
-> ((zap> . +relation) (zap> . +Blob) (zap> . +Entity))
: (more @ pp)
(dm (zap> . +relation) (Obj Val))
(dm (zap> . +Blob) (Obj Val)
(and
Val
(call 'rm "-f" (blob Obj (: var))) ) )
(dm (zap> . +Entity) NIL
(for X (getl This)
(let V (or (atom X) (pop 'X))
(and (meta This X) (zap> @ This V)) ) ) )
-> NIL
</code></pre>
<dt><a name="car"><code>(car 'var) -> any</code></a>
<dd>List access: Returns the value of <code>var</code> if it is a symbol, or the
first element if it is a list. See also <code><a
href="refC.html#cdr">cdr</a></code> and <code><a
href="refC.html#cXr">c..r</a></code>.
<pre><code>
: (car (1 2 3 4 5 6))
-> 1
</code></pre>
<dt><a name="cXr"><code>(c[ad]*ar 'var) -> any</code></a>
<dt><code>(c[ad]*dr 'lst) -> any</code>
<dd>List access shortcuts. Combinations of the <code><a
href="refC.html#car">car</a></code> and <code><a
href="refC.html#cdr">cdr</a></code> functions, with up to four letters 'a' and
'd'.
<pre><code>
: (cdar '((1 . 2) . 3))
-> 2
</code></pre>
<dt><a name="case"><code>(case 'any (any1 . prg1) (any2 . prg2) ..) -> any</code></a>
<dd>Multi-way branch: <code>any</code> is evaluated and compared to the CAR
elements <code>anyN</code> of each clause. If one of them is a list,
<code>any</code> is in turn compared to all elements of that list.
<code>T</code> is a catch-all for any value. If a comparison succeeds,
<code>prgN</code> is executed, and the result returned. Otherwise
<code>NIL</code> is returned. See also <code><a
href="refS.html#state">state</a></code>.
<pre><code>
: (case (char 66) ("A" (+ 1 2 3)) (("B" "C") "Bambi") ("D" (* 1 2 3)))
-> "Bambi"
</code></pre>
<dt><a name="catch"><code>(catch 'any . prg) -> any</code></a>
<dd>Sets up the environment for a non-local jump which may be caused by <code><a
href="refT.html#throw">throw</a></code> or by a runtime error. If
<code>any</code> is an atom, it is used by <code>throw</code> as a jump label
(with <code>T</code> being a catch-all for any label), and a <code>throw</code>
called during the execution of <code>prg</code> will immediately return the
thrown value. Otherwise, <code>any</code> should be a list of strings, to catch
any error whose message contains one of these strings, and this will immediately
return the matching string. If neither <code>throw</code> nor an error occurs,
the result of <code>prg</code> is returned. See also <code><a
href="refF.html#finally">finally</a></code>, <code><a
href="refQ.html#quit">quit</a></code> and
<code><a href="ref.html#errors">Error Handling</a></code>.
<pre><code>
: (catch 'OK (println 1) (throw 'OK 999) (println 2))
1
-> 999
: (catch '("No such file") (in "doesntExist" (foo)))
-> "No such file"
</code></pre>
<dt><a name="cd"><code>(cd 'any) -> sym</code></a>
<dd>Changes the current directory to <code>any</code>. The old directory is
returned on success, otherwise <code>NIL</code>. See also <code><a
href="refD.html#dir">dir</a></code> and <code><a
href="refP.html#pwd">pwd</a></code>.
<pre><code>
: (when (cd "lib")
(println (sum lines (dir)))
(cd @) )
10955
</code></pre>
<dt><a name="cdr"><code>(cdr 'lst) -> any</code></a>
<dd>List access: Returns all but the first element of <code>lst</code>. See also
<code><a href="refC.html#car">car</a></code> and <code><a
href="refC.html#cXr">c..r</a></code>.
<pre><code>
: (cdr (1 2 3 4 5 6))
-> (2 3 4 5 6)
</code></pre>
<dt><a name="center"><code>(center 'cnt|lst 'any ..) -> sym</code></a>
<dd>Returns a transient symbol with all <code>any</code> arguments <code><a
href="refP.html#pack">pack</a></code>ed in a centered format. Trailing blanks
are omitted. See also <code><a href="refA.html#align">align</a></code>, <code><a
href="refT.html#tab">tab</a></code> and <code><a
href="refW.html#wrap">wrap</a></code>.
<pre><code>
: (center 4 12)
-> " 12"
: (center 4 "a")
-> " a"
: (center 7 "a")
-> " a"
: (center (3 3 3) "a" "b" "c")
-> " a b c"
</code></pre>
<dt><a name="chain"><code>(chain 'lst ..) -> lst</code></a>
<dd>Concatenates (destructively) one or several new list elements
<code>lst</code> to the end of the list in the current <code><a
href="refM.html#make">make</a></code> environment. This operation is efficient
also for long lists, because a pointer to the last element of the result list is
maintained. <code>chain</code> returns the last linked argument. See also
<code><a href="refL.html#link">link</a></code>, <code><a
href="refY.html#yoke">yoke</a></code> and <code><a
href="refM.html#made">made</a></code>.
<pre><code>
: (make (chain (list 1 2 3) NIL (cons 4)) (chain (list 5 6)))
-> (1 2 3 4 5 6)
</code></pre>
<dt><a name="char"><code>(char) -> sym</code></a>
<dt><code>(char 'cnt) -> sym</code>
<dt><code>(char T) -> sym</code>
<dt><code>(char 'sym) -> cnt</code>
<dd>When called without arguments, the next character from the current input
stream is returned as a single-character transient symbol, or <code>NIL</code>
upon end of file. When called with a number <code>cnt</code>, a character with
the corresponding unicode value is returned. As a special case, <code>T</code>
is accepted to produce a byte value greater than any first byte in a UTF-8
character (used as a top value in comparisons). Otherwise, when called with a
symbol <code>sym</code>, the numeric unicode value of the first character of the
name of that symbol is returned. See also <code><a
href="refP.html#peek">peek</a></code>, <code><a
href="refS.html#skip">skip</a></code>, <code><a
href="refK.html#key">key</a></code>, <code><a
href="refL.html#line">line</a></code>, <code><a
href="refT.html#till">till</a></code> and <code><a
href="refE.html#eof">eof</a></code>.
<pre><code>
: (char) # Read character from console
A # (typed 'A' and a space/return)
-> "A"
: (char 100) # Convert unicode to symbol
-> "d"
: (char "d") # Convert symbol to unicode
-> 100
: (char T) # Special case
-> # (not printable)
: (char 0)
-> NIL
: (char NIL)
-> 0
</code></pre>
<dt><a name="chdir"><code>(chdir 'any . prg) -> any</code></a>
<dd>Changes the current directory to <code>any</code> with <code><a
href="refC.html#cd">cd</a></code> during the execution of <code>prg</code>. Then
the previous directory will be restored and the result of <code>prg</code>
returned. See also <code><a href="refD.html#dir">dir</a></code> and <code><a
href="refP.html#pwd">pwd</a></code>.
<pre><code>
: (pwd)
-> "/usr/abu/pico"
: (chdir "src" (pwd))
-> "/usr/abu/pico/src"
: (pwd)
-> "/usr/abu/pico"
</code></pre>
<dt><a name="chkTree"><code>(chkTree 'sym ['fun]) -> num</code></a>
<dd>Checks a database tree node (and recursively all sub-nodes) for consistency.
Returns the total number of nodes checked. Optionally, <code>fun</code> is
called with the key and value of each node, and should return <code>NIL</code>
for failure. See also <code><a href="refT.html#tree">tree</a></code> and
<code><a href="refR.html#root">root</a></code>.
<pre><code>
: (show *DB '+Item)
{C} NIL
sup (7 . {7-3})
nr (7 . {7-1}) # 7 nodes in the 'nr' tree, base node is {7-1}
pr (7 . {7-4})
nm (77 . {7-6})
-> {C}
: (chkTree '{7-1}) # Check that node
-> 7
</code></pre>
<dt><a name="chop"><code>(chop 'any) -> lst</code></a>
<dd>Returns <code>any</code> as a list of single-character strings. If
<code>any</code> is <code>NIL</code> or a symbol with no name, <code>NIL</code>
is returned. A list argument is returned unchanged.
<pre><code>
: (chop 'car)
-> ("c" "a" "r")
: (chop "Hello")
-> ("H" "e" "l" "l" "o")
</code></pre>
<dt><a name="circ"><code>(circ 'any ..) -> lst</code></a>
<dd>Produces a circular list of all <code>any</code> arguments by <code><a
href="refC.html#cons">cons</a></code>ing them to a list and then connecting the
CDR of the last cell to the first cell. See also <code><a
href="refC.html#circ?">circ?</a></code> and <code><a
href="refL.html#list">list</a></code>.
<pre><code>
: (circ 'a 'b 'c)
-> (a b c .)
</code></pre>
<dt><a name="circ?"><code>(circ? 'any) -> any</code></a> <dd>Returs the circular
(sub)list if <code>any</code> is a circular list, else <code>NIL</code>. See
also <code><a href="refC.html#circ">circ</a></code>.
<pre><code>
: (circ? 'a)
-> NIL
: (circ? (1 2 3))
-> NIL
: (circ? (1 . (2 3 .)))
-> (2 3 .)
</code></pre>
<dt><a name="class"><code>(class sym . typ) -> obj</code></a>
<dd>Defines <code>sym</code> as a class with the superclass(es)
<code>typ</code>. As a side effect, the global variable <code><a
href="refC.html#*Class">*Class</a></code> is set to <code>obj</code>. See also
<code><a href="refE.html#extend">extend</a></code>, <code><a
href="refD.html#dm">dm</a></code>, <code><a href="refV.html#var">var</a></code>,
<code><a href="refR.html#rel">rel</a></code>, <code><a
href="refT.html#type">type</a></code>, <code><a
href="refI.html#isa">isa</a></code> and <code><a
href="refO.html#object">object</a></code>.
<pre><code>
: (class +A +B +C +D)
-> +A
: +A
-> (+B +C +D)
: (dm foo> (X) (bar X))
-> foo>
: +A
-> ((foo> (X) (bar X)) +B +C +D)
</code></pre>
<dt><a name="clause"><code>(clause '(sym . any)) -> sym</code></a>
<dd>Declares a <a href="ref.html#pilog">Pilog</a> fact or rule for the
<code>sym</code> argument, by concatenating the <code>any</code> argument to the
<code>T</code> property of <code>sym</code>. See also <code><a
href="refB.html#be">be</a></code>.
<pre><code>
: (clause '(likes (John Mary)))
-> likes
: (clause '(likes (John @X) (likes @X wine) (likes @X food)))
-> likes
: (? (likes @X @Y))
@X=John @Y=Mary
-> NIL
</code></pre>
<dt><a name="clause/2"><code>clause/2</code></a>
<dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if the first
argument is a predicate which has the second argument defined as a clause.
<pre><code>
: (? (clause append ((NIL @X @X))))
-> T
: (? (clause append @C))
@C=((NIL @X @X))
@C=(((@A . @X) @Y (@A . @Z)) (append @X @Y @Z))
-> NIL
</code></pre>
<dt><a name="clip"><code>(clip 'lst) -> lst</code></a>
<dd>Returns a copy of <code>lst</code> with all whitespace characters or
<code>NIL</code> elements removed from both sides. See also <code><a
href="refT.html#trim">trim</a></code>.
<pre><code>
: (clip '(NIL 1 NIL 2 NIL))
-> (1 NIL 2)
: (clip '(" " a " " b " "))
-> (a " " b)
</code></pre>
<dt><a name="close"><code>(close 'cnt) -> cnt | NIL</code></a>
<dd>Closes a file descriptor <code>cnt</code>, and returns it when successful.
Should not be called inside an <code><a href="refO.html#out">out</a></code> body
for that descriptor. See also <code><a href="refO.html#open">open</a></code>,
<code><a href="refP.html#poll">poll</a></code>,
<code><a href="refL.html#listen">listen</a></code> and <code><a
href="refC.html#connect">connect</a></code>.
<pre><code>
: (close 2) # Close standard error
-> 2
</code></pre>
<dt><a name="cmd"><code>(cmd ['any]) -> sym</code></a>
<dd>When called without an argument, the name of the command that invoked the
picolisp interpreter is returned. Otherwise, the command name is set to
<code>any</code>. Setting the name may not work on some operating systems. Note
that the new name must not be longer than the original one. See also <code><a
href="refA.html#argv">argv</a></code>, <code><a
href="refF.html#file">file</a></code> and <a
href="ref.html#invoc">Invocation</a>.
<pre><code>
$ pil +
: (cmd)
-> "/usr/bin/picolisp"
: (cmd "!/bin/picolust")
-> "!/bin/picolust"
: (cmd)
-> "!/bin/picolust"
</code></pre>
<dt><a name="cnt"><code>(cnt 'fun 'lst ..) -> cnt</code></a>
<dd>Applies <code>fun</code> to each element of <code>lst</code>. When
additional <code>lst</code> arguments are given, their elements are also passed
to <code>fun</code>. Returns the count of non-<code>NIL</code> values returned
from <code>fun</code>.
<pre><code>
: (cnt cdr '((1 . T) (2) (3 4) (5)))
-> 2
</code></pre>
<dt><a name="collect"><code>(collect 'var 'cls ['hook] ['any|beg ['end [var ..]]])</code></a>
<dd>Returns a list of all database objects of class <code>cls</code>, where the
values for the <code>var</code> arguments correspond to the <code>any</code>
arguments, or where the values for the <code>var</code> arguments are in the
range <code>beg</code> .. <code>end</code>. <code>var</code>, <code>cls</code>
and <code>hook</code> should specify a <code><a
href="refT.html#tree">tree</a></code> for <code>cls</code> or one of its
superclasses. If additional <code>var</code> arguments are given, the final
values for the result list are obtained by applying the <code><a
href="refG.html#get">get</a></code> algorithm. See also <code><a
href="refD.html#db">db</a></code>, <code><a href="refA.html#aux">aux</a></code>,
<code><a href="refF.html#fetch">fetch</a></code>, <code><a
href="refI.html#init">init</a></code> and <code><a
href="refS.html#step">step</a></code>.
<pre><code>
: (collect 'nr '+Item)
-> ({3-1} {3-2} {3-3} {3-4} {3-5} {3-6} {3-8})
: (collect 'nr '+Item 3 6 'nr)
-> (3 4 5 6)
: (collect 'nr '+Item 3 6 'nm)
-> ("Auxiliary Construction" "Enhancement Additive" "Metal Fittings" "Gadget Appliance")
: (collect 'nm '+Item "Main Part")
-> ({3-1})
</code></pre>
<dt><a name="commit"><code>(commit ['any] [exe1] [exe2]) -> T</code></a>
<dd>Closes a transaction, by writing all new or modified external symbols to,
and removing all deleted external symbols from the database. When
<code>any</code> is given, it is implicitly sent (with all modified objects) via
the <code><a href="refT.html#tell">tell</a></code> mechanism to all family
members. If <code>exe1</code> or <code>exe2</code> are given, they are executed
as pre- or post-expressions while the database is <code><a
href="refL.html#lock">lock</a></code>ed and <code><a
href="refP.html#protect">protect</a></code>ed. See also <code><a
href="refR.html#rollback">rollback</a></code>.
<pre><code>
: (pool "db")
-> T
: (put '{1} 'str "Hello")
-> "Hello"
: (commit)
-> T
</code></pre>
<dt><a name="con"><code>(con 'lst 'any) -> any</code></a>
<dd>Connects <code>any</code> to the first cell of <code>lst</code>, by
(destructively) storing <code>any</code> in the CDR of <code>lst</code>. See
also <code><a href="refC.html#conc">conc</a></code>.
<pre><code>
: (setq C (1 . a))
-> (1 . a)
: (con C '(b c d))
-> (b c d)
: C
-> (1 b c d)
</code></pre>
<dt><a name="conc"><code>(conc 'lst ..) -> lst</code></a>
<dd>Concatenates all argument lists (destructively). See also <code><a
href="refA.html#append">append</a></code> and <code><a
href="refC.html#con">con</a></code>.
<pre><code>
: (setq A (1 2 3) B '(a b c))
-> (a b c)
: (conc A B) # Concatenate lists in 'A' and 'B'
-> (1 2 3 a b c)
: A
-> (1 2 3 a b c) # Side effect: List in 'A' is modified!
</code></pre>
<dt><a name="cond"><code>(cond ('any1 . prg1) ('any2 . prg2) ..) -> any</code></a>
<dd>Multi-way conditional: If any of the <code>anyN</code> conditions evaluates
to non-<code>NIL</code>, <code>prgN</code> is executed and the result returned.
Otherwise (all conditions evaluate to <code>NIL</code>), <code>NIL</code> is
returned. See also <code><a href="refN.html#nond">nond</a></code>, <code><a
href="refI.html#if">if</a></code>, <code><a href="refI.html#if2">if2</a></code>
and <code><a href="refW.html#when">when</a></code>.
<pre><code>
: (cond
((= 3 4) (println 1))
((= 3 3) (println 2))
(T (println 3)) )
2
-> 2
</code></pre>
<dt><a name="connect"><code>(connect 'any1 'any2) -> cnt | NIL</code></a>
<dd>Tries to establish a TCP/IP connection to a server listening at host
<code>any1</code>, port <code>any2</code>. <code>any1</code> may be either a
hostname or a standard internet address in numbers-and-dots/colons notation
(IPv4/IPv6). <code>any2</code> may be either a port number or a service name.
Returns a socket descriptor <code>cnt</code>, or <code>NIL</code> if the
connection cannot be established. See also <code><a
href="refL.html#listen">listen</a></code> and <code><a
href="refU.html#udp">udp</a></code>.
<pre><code>
: (connect "localhost" 4444)
-> 3
: (connect "some.host.org" "http")
-> 4
</code></pre>
<dt><a name="cons"><code>(cons 'any ['any ..]) -> lst</code></a>
<dd>Constructs a new list cell with the first argument in the CAR and the second
argument in the CDR. If more than two arguments are given, a corresponding chain
of cells is built. <code>(cons 'a 'b 'c 'd)</code> is equivalent to <code>(cons
'a (cons 'b (cons 'c 'd)))</code>. See also <code><a
href="refL.html#list">list</a></code>.
<pre><code>
: (cons 1 2)
-> (1 . 2)
: (cons 'a '(b c d))
-> (a b c d)
: (cons '(a b) '(c d))
-> ((a b) c d)
: (cons 'a 'b 'c 'd)
-> (a b c . d)
</code></pre>
<dt><a name="copy"><code>(copy 'any) -> any</code></a>
<dd>Copies the argument <code>any</code>. For lists, the top level cells are
copied, while atoms are returned unchanged.
<pre><code>
: (=T (copy T)) # Atoms are not copied
-> T
: (setq L (1 2 3))
-> (1 2 3)
: (== L L)
-> T
: (== L (copy L)) # The copy is not identical to the original
-> NIL
: (= L (copy L)) # But the copy is equal to the original
-> T
</code></pre>
<dt><a name="co"><code>(co 'sym [. prg]) -> any</code></a>
<dd>(64-bit version only) Starts, resumes or stops a <a
href="ref.html#coroutines">coroutine</a> with the tag given by <code>sym</code>.
If <code>prg</code> is not given, a coroutine with that tag will be stopped.
Otherwise, if a coroutine running with that tag is found (pointer equality is
used for comparison), its execution is resumed. Else a new coroutine with that
tag is initialized and started. <code>prg</code> will be executed until it
either terminates normally, or until <code><a
href="refY.html#yield">yield</a></code> is called. In the latter case
<code>co</code> returns, or transfers control to some other, already running,
coroutine. Trying to start more than 64 coroutines will result in a stack
overflow error. Also, a coroutine cannot resume itself directly or indirectly.
See also <code><a href="refS.html#stack">stack</a></code>, <code><a
href="refC.html#catch">catch</a></code> and <code><a
href="refT.html#throw">throw</a></code>.
<pre><code>
: (de pythag (N) # A generator function
(if (=T N)
(co 'rt) # Stop
(co 'rt
(for X N
(for Y (range X N)
(for Z (range Y N)
(when (= (+ (* X X) (* Y Y)) (* Z Z))
(yield (list X Y Z)) ) ) ) ) ) ) )
: (pythag 20)
-> (3 4 5)
: (pythag 20)
-> (5 12 13)
: (pythag 20)
-> (6 8 10)
</code></pre>
<dt><a name="count"><code>(count 'tree) -> num</code></a>
<dd>Returns the number of nodes in a database tree. See also <code><a
href="refT.html#tree">tree</a></code> and <code><a
href="refR.html#root">root</a></code>.
<pre><code>
: (count (tree 'nr '+Item))
-> 7
</code></pre>
<dt><a name="ctl"><code>(ctl 'sym . prg) -> any</code></a>
<dd>Waits until a write (exclusive) lock (or a read (shared) lock if the first
character of <code>sym</code> is "<code>+</code>") can be set on the file
<code>sym</code>, then executes <code>prg</code> and releases the lock. If the
files does not exist, it will be created. When <code>sym</code> is
<code>NIL</code>, a shared lock is tried on the current innermost I/O channel,
and when it is <code>T</code>, an exclusive lock is tried instead. See also
<code><a href="refI.html#in">in</a></code>, <code><a
href="refO.html#out">out</a></code>, <code><a
href="refE.html#err">err</a></code> and <code><a
href="refP.html#pipe">pipe</a></code>.
<pre><code>
$ echo 9 >count # Write '9' to file "count"
$ pil +
: (ctl ".ctl" # Exclusive control, using ".ctl"
(in "count"
(let Cnt (read) # Read '9'
(out "count"
(println (dec Cnt)) ) ) ) ) # Write '8'
-> 8
:
$ cat count # Check "count"
8
</code></pre>
<dt><a name="ctty"><code>(ctty 'sym|pid) -> flg</code></a>
<dd>When called with a symbolic argument, <code>ctty</code> changes the current
TTY device to <code>sym</code>. Otherwise, the local console is prepared for
serving the PicoLisp process with the process ID <code>pid</code>. See also
<code><a href="refR.html#raw">raw</a></code>.
<pre><code>
: (ctty "/dev/tty")
-> T
</code></pre>
<dt><a name="curry"><code>(curry lst . fun) -> fun</code></a>
<dd>Builds a new function from the list of symbols or symbol-value pairs
<code>lst</code> and the functional expression <code>fun</code>. Each member in
<code>lst</code> that is a <code><a href="refP.html#pat?">pat?</a></code> symbol
is substituted inside <code>fun</code> by its value. All other symbols in
<code>lst</code> are collected into a <code><a
href="refJ.html#job">job</a></code> environment.
<pre><code>
: (de multiplier (@X)
(curry (@X) (N) (* @X N)) )
-> multiplier
: (multiplier 7)
-> ((N) (* 7 N))
: ((multiplier 7) 3))
-> 21
: (def 'fiboCounter
(curry ((N1 . 0) (N2 . 1)) (Cnt)
(do Cnt
(println
(prog1
(+ N1 N2)
(setq N1 N2 N2 @) ) ) ) ) )
-> fiboCounter
: (pp 'fiboCounter)
(de fiboCounter (Cnt)
(job '((N2 . 1) (N1 . 0))
(do Cnt
(println
(prog1 (+ N1 N2) (setq N1 N2 N2 @)) ) ) ) )
-> fiboCounter
: (fiboCounter 5)
1
2
3
5
8
-> 8
: (fiboCounter 5)
13
21
34
55
89
-> 89
</code></pre>
<dt><a name="cut"><code>(cut 'cnt 'var) -> lst</code></a>
<dd>Pops the first <code>cnt</code> elements (CAR) from the stack in
<code>var</code>. See also <code><a href="refP.html#pop">pop</a></code> and
<code><a href="refD.html#del">del</a></code>.
<pre><code>
: (setq S '(1 2 3 4 5 6 7 8))
-> (1 2 3 4 5 6 7 8)
: (cut 3 'S)
-> (1 2 3)
: S
-> (4 5 6 7 8)
</code></pre>
</dl>
</body>
</html>
|