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