picolisp

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

refN.html (15714B)


      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>N</title>
      6 <link rel="stylesheet" href="doc.css" type="text/css">
      7 </head>
      8 <body>
      9 
     10 <h1>N</h1>
     11 
     12 <dl>
     13 
     14 <dt><a name="+Need"><code>+Need</code></a>
     15 <dd>Prefix class for mandatory <code><a
     16 href="refR.html#+relation">+relation</a></code>s. Note that this does not
     17 enforce any requirements by itself, it only returns an error message if the
     18 <code>mis&gt;</code> message is explicitly called, e.g. by GUI functions. See
     19 also <a href="ref.html#dbase">Database</a>.
     20 
     21 <pre><code>
     22 (rel nr (+Need +Key +Number))  # Item number is mandatory
     23 </code></pre>
     24 
     25 <dt><a name="+Number"><code>+Number</code></a>
     26 <dd>Class for numeric relations, a subclass of <code><a
     27 href="refR.html#+relation">+relation</a></code>. Accepts an optional argument
     28 for the fixpoint scale (currently not used). See also <a
     29 href="ref.html#dbase">Database</a>.
     30 
     31 <pre><code>
     32 (rel pr (+Number) 2)  # Price, with two decimal places
     33 </code></pre>
     34 
     35 <dt><a name="n=="><code>(n== 'any ..) -> flg</code></a>
     36 <dd>Returns <code>T</code> when not all <code>any</code> arguments are the same
     37 (pointer equality). <code>(n== 'any ..)</code> is equivalent to <code>(not (==
     38 'any ..))</code>. See also <code><a href="ref_.html#==">==</a></code> and <a
     39 href="ref.html#cmp">Comparing</a>.
     40 
     41 <pre><code>
     42 : (n== 'a 'a)
     43 -> NIL
     44 : (n== (1) (1))
     45 -> T
     46 </code></pre>
     47 
     48 <dt><a name="n0"><code>(n0 'any) -> flg</code></a>
     49 <dd>Returns <code>T</code> when <code>any</code> is not a number with value
     50 zero. See also <code><a href="ref_.html#=0">=0</a></code>, <code><a
     51 href="refL.html#lt0">lt0</a></code>, <code><a
     52 href="refL.html#le0">le0</a></code>, <code><a
     53 href="refG.html#ge0">ge0</a></code> and <code><a
     54 href="refG.html#gt0">gt0</a></code>.
     55 
     56 <pre><code>
     57 : (n0 (- 6 3 2 1))
     58 -> NIL
     59 : (n0 'a)
     60 -> T
     61 </code></pre>
     62 
     63 <dt><a name="nT"><code>(nT 'any) -> flg</code></a>
     64 <dd>Returns <code>T</code> when <code>any</code> is not the symbol
     65 <code>T</code>. See also <a href="ref_.html#=T">=T</a>.
     66 
     67 <pre><code>
     68 : (nT 0)
     69 -> T
     70 : (nT "T")
     71 -> T
     72 : (nT T)
     73 -> NIL
     74 </code></pre>
     75 
     76 <dt><a name="name"><code>(name 'sym ['sym2]) -> sym</code></a>
     77 <dd>Returns, if <code>sym2</code> is not given, a new transient symbol with the
     78 name of <code>sym</code>. Otherwise <code>sym</code> must be a transient symbol,
     79 and its name is changed to that of <code>sym2</code> (note that this may give
     80 inconsistencies if the symbol is still referred to from other namespaces). See
     81 also <code><a href="refS.html#str">str</a></code>, <code><a
     82 href="refS.html#sym">sym</a></code>, <code><a
     83 href="refS.html#symbols">symbols</a></code>, <code><a
     84 href="refZ.html#zap">zap</a></code> and <code><a
     85 href="refI.html#intern">intern</a></code>.
     86 
     87 <pre><code>
     88 : (name 'abc)
     89 -> "abc"
     90 : (name "abc")
     91 -> "abc"
     92 : (name '{abc})
     93 -> "abc"
     94 : (name (new))
     95 -> NIL
     96 : (de foo (Lst) (car Lst))  # 'foo' calls 'car'
     97 -> foo
     98 : (intern (name (zap 'car) "xxx"))  # Globally change the name of 'car'
     99 -> xxx
    100 : (xxx (1 2 3))
    101 -> 1
    102 : (pp 'foo)
    103 (de foo (Lst)
    104    (xxx Lst) )                      # Name changed
    105 -> foo
    106 : (foo (1 2 3))                     # 'foo' still works
    107 -> 1
    108 : (car (1 2 3))                     # Reader returns a new 'car' symbol
    109 !? (car (1 2 3))
    110 car -- Undefined
    111 ?
    112 </code></pre>
    113 
    114 <dt><a name="nand"><code>(nand 'any ..) -> flg</code></a>
    115 <dd>Logical NAND. The expressions <code>any</code> are evaluated from left to
    116 right. If <code>NIL</code> is encountered, <code>T</code> is returned
    117 immediately. Else <code>NIL</code> is returned. <code>(nand ..)</code> is
    118 equivalent to <code>(not (and ..))</code>.
    119 
    120 <pre><code>
    121 : (nand (lt0 7) (read))
    122 -> T
    123 : (nand (lt0 -7) (read))
    124 abc
    125 -> NIL
    126 : (nand (lt0 -7) (read))
    127 NIL
    128 -> T
    129 </code></pre>
    130 
    131 <dt><a name="native"><code>(native 'cnt1|sym1 'cnt2|sym2 'any 'any ..) -> any</code></a>
    132 <dd>(64-bit version only) Calls a native C function. The first argument should
    133 specify a shared object library, either <code>"@"</code> (the current main
    134 program), <code>sym1</code> (a library path name), or <code>cnt1</code> (a
    135 library handle obtained by a previous call). The second argument should be a
    136 symbol name <code>sym2</code>, or a function pointer <code>cnt2</code> obtained
    137 by a previous call). Practically, the first two arguments will be always passed
    138 as transient symbols, which will get the library handle and function pointer
    139 assigned as values to be cached and used in subsequent calls. The third argument
    140 <code>any</code> is a result specification, while all following arguments are
    141 the arguments to the native function. The functionality is described in detail
    142 in <a href="native.html">Native C Calls</a>.
    143 
    144 <p><a name="natResult">The result specification</a> may either be one of the
    145 atoms
    146 
    147 <pre><code>
    148    NIL   void
    149    B     byte     # Byte (unsigned 8 bit)
    150    C     char     # Character (UTF-8, 1-3 bytes)
    151    I     int      # Integer (signed 32 bit)
    152    N     long     # Long or pointer (signed 64 bit)
    153    S     string   # String (UTF-8)
    154   -1.0   float    # Scaled fixpoint number
    155   +1.0   double   # Scaled fixpoint number
    156 </code></pre>
    157 
    158 <p>or nested lists of these atoms with size specifications to denote arrays and
    159 structures, e.g.
    160 
    161 <pre><code>
    162    (N . 4)        # long[4];           -> (1 2 3 4)
    163    (N (C . 4))    # {long; char[4];}   -> (1234 ("a" "b" "c" NIL))
    164    (N (B . 7))    # {long; byte[7];}   -> (1234 (1 2 3 4 5 6 7))
    165 </code></pre>
    166 
    167 <p>Arguments can be
    168 <ul>
    169 <li>integers (up to 64-bit) or pointers, passed as numbers
    170 <li>strings, passed as symbols
    171 <li>fixpoint numbers, passed as cons pairs consisting of a the value and the
    172    scale (if the scale is positive, the number is passed as a
    173    <code>double</code>, otherwise as a <code>float</code>)
    174 <li>structures, passed as lists with
    175    <ul>
    176    <li>a variable in the CAR (to recieve the returned structure data, ignored
    177       when the CAR is <code>NIL</code>)
    178    <li>a cons pair for the size and result specification in the CADR (see
    179       above), and
    180    <li>an optional sequence of <a name="natItem">initialization items</a> in the
    181       CDDR, where each may be
    182       <ul>
    183       <li>a positive number, stored as an unsigned byte value
    184       <li>a negative number, whose absolute value is stored as an unsigned
    185          integer
    186       <li>a pair <code>(num . cnt)</code> where '<code>num</code>' is stored in
    187          a field of '<code>cnt</code>' bytes
    188       <li>a pair <code>(sym . cnt)</code> where '<code>sym</code>' is stored as
    189          a null-terminated string in a field of '<code>cnt</code>' bytes
    190       <li>a list <code>(1.0 num ...)</code> where the '<code>num</code>'
    191          elements (scaled fixpoint numbers) are stored as a sequence of double
    192          precision floating point numbers
    193       <li>a list <code>(-1.0 num ...)</code> where the '<code>num</code>'
    194          elements (scaled fixpoint numbers) are stored as a sequence of single
    195          precision floating point numbers
    196       </ul>
    197       If the last CDR of the initialization sequence is a number, it is used
    198       as a fill-byte value for the remaining space in the structure.
    199    </ul>
    200 </ul>
    201 
    202 <p><code>native</code> takes care of allocating memory for strings, arrays or
    203 structures, and frees that memory when done.
    204 
    205 <p>The number of fixpoint arguments is limited to six. For NaN or negative
    206 infinity <code>NIL</code>, and for positive infinity <code>T</code> is returned.
    207 
    208 <p>The C function may in turn call a function
    209 
    210 <pre><code>
    211    long lisp(char*, long, long, long, long, long);
    212 </code></pre>
    213 
    214 <p>which accepts a symbol name as the first argument, and up to 5 numbers.
    215 <code>lisp()</code> calls that symbol with the five numbers, and expects a
    216 numeric return value. "Numbers" in this context are 64-bit scalars, and may not
    217 only represent integers, but also pointers or other encoded data. See also
    218 <code><a href="refS.html#struct">struct</a></code>, <code><a
    219 href="refL.html#lisp">lisp</a></code> and <code><a
    220 href="refE.html#errno">errno</a></code>.
    221 
    222 <pre><code>
    223 : (native "@" "getenv" 'S "TERM")  # Same as (sys "TERM")
    224 -> "xterm"
    225 
    226 : (native "@" "printf" 'I "abc%d%s^J" (+ 3 4) (pack "X" "Y" "Z"))
    227 abc7XYZ
    228 -> 8
    229 
    230 : (native "@" "printf" 'I "This is %.3f^J" (123456 . 1000))
    231 This is 123.456
    232 -> 16
    233 
    234 : (use Tim
    235    (native "@" "time" NIL '(Tim (8 B . 8)))  # time_t 8   # Get time_t structure
    236    (native "@" "localtime" '(I . 9) (cons NIL (8) Tim)) ) # Read local time
    237 -> (32 18 13 31 11 109 4 364 0)  # 13:18:32, Dec. 31st, 2009
    238 
    239 : (native "libcrypto.so" "SHA1" '(B . 20) "abcd" 4 0)
    240 -> (129 254 139 254 135 87 108 62 203 34 66 111 142 87 132 115 130 145 122 207)
    241 </code></pre>
    242 
    243 <dt><a name="need"><code>(need 'cnt ['lst ['any]]) -> lst</code></a>
    244 <dt><code>(need 'cnt ['num|sym]) -> lst</code>
    245 <dd>Produces a list of at least <code>cnt</code> elements. When called without
    246 optional arguments, a list of <code>cnt</code> <code>NIL</code>'s is returned.
    247 When <code>lst</code> is given, it is extended to the left (if <code>cnt</code>
    248 is positive) or (destructively) to the right (if <code>cnt</code> is negative)
    249 with <code>any</code> elements. In the second form, a list of <code>cnt</code>
    250 atomic values is returned. See also <code><a
    251 href="refR.html#range">range</a></code>.
    252 
    253 <pre><code>
    254 : (need 5)
    255 -> (NIL NIL NIL NIL NIL)  # Allocate 5 cells
    256 : (need 5 '(a b c))
    257 -> (NIL NIL a b c)
    258 : (need -5 '(a b c))
    259 -> (a b c NIL NIL)
    260 : (need 5 '(a b c) " ")  # String alignment
    261 -> (" " " " a b c)
    262 : (need 7 0)
    263 -> (0 0 0 0 0 0 0)
    264 </code></pre>
    265 
    266 <dt><a name="new"><code>(new ['flg|num] ['typ ['any ..]]) -> obj</code></a>
    267 <dd>Creates and returns a new object. If <code>flg</code> is given and
    268 non-<code>NIL</code>, the new object will be an external symbol (created in
    269 database file 1 if <code>T</code>, or in the corresponding database file if
    270 <code>num</code> is given). <code>typ</code> (typically a list of classes) is
    271 assigned to the <code>VAL</code>, and the initial <code>T</code> message is sent
    272 with the arguments <code>any</code> to the new object. If no <code>T</code>
    273 message is defined for the classes in <code>typ</code> or their superclasses,
    274 the <code>any</code> arguments should evaluate to alternating keys and values
    275 for the initialization of the new object. See also <code><a
    276 href="refB.html#box">box</a></code>, <code><a
    277 href="refO.html#object">object</a></code>, <code><a
    278 href="refC.html#class">class</a></code>, <code><a
    279 href="refT.html#type">type</a></code>, <code><a
    280 href="refI.html#isa">isa</a></code>, <code><a
    281 href="refS.html#send">send</a></code> and <a href="ref.html#dbase">Database</a>.
    282 
    283 <pre><code>
    284 : (new)
    285 -> $134426427
    286 : (new T '(+Address))
    287 -> {1A;3}
    288 </code></pre>
    289 
    290 <dt><a name="new!"><code>(new! 'typ ['any ..]) -> obj</code></a>
    291 <dd><a href="ref.html#trans">Transaction</a> wrapper function for <code><a
    292 href="refN.html#new">new</a></code>. <code>(new! '(+Cls) 'key 'val ...)</code>
    293 is equivalent to <code>(dbSync) (new (db: +Cls) '(+Cls) 'key 'val ...) (commit
    294 'upd)</code>. See also <code><a href="refS.html#set!">set!</a></code>, <code><a
    295 href="refP.html#put!">put!</a></code> and <code><a
    296 href="refI.html#inc!">inc!</a></code>.
    297 
    298 <pre><code>
    299 : (new! '(+Item)  # Create a new item
    300    'nr 2                      # Item number
    301    'nm "Spare Part"           # Description
    302    'sup (db 'nr '+CuSu 2)     # Supplier
    303    'inv 100                   # Inventory
    304    pr 12.50 )                 # Price
    305 </code></pre>
    306 
    307 <dt><a name="next"><code>(next) -> any</code></a>
    308 <dd>Can only be used inside functions with a variable number of arguments (with
    309 <code>@</code>). Returns the next argument from the internal list. See also
    310 <code><a href="refA.html#args">args</a></code>, <code><a
    311 href="refA.html#arg">arg</a></code>, <code><a
    312 href="refR.html#rest">rest</a></code>, and <code><a
    313 href="refP.html#pass">pass</a></code>.
    314 
    315 <pre><code>
    316 : (de foo @ (println (next)))          # Print next argument
    317 -> foo
    318 : (foo)
    319 NIL
    320 -> NIL
    321 : (foo 123)
    322 123
    323 -> 123
    324 </code></pre>
    325 
    326 <dt><a name="nil"><code>(nil . prg) -> NIL</code></a>
    327 <dd>Executes <code>prg</code>, and returns <code>NIL</code>. See also <code><a
    328 href="refT.html#t">t</a></code>, <code><a href="refP.html#prog">prog</a></code>,
    329 <code><a href="refP.html#prog1">prog1</a></code> and <code><a
    330 href="refP.html#prog2">prog2</a></code>.
    331 
    332 <pre><code>
    333 : (nil (println 'OK))
    334 OK
    335 -> NIL
    336 </code></pre>
    337 
    338 <dt><a name="nil/1"><code>nil/1</code></a>
    339 <dd><a href="ref.html#pilog">Pilog</a> predicate expects an argument variable,
    340 and succeeds if that variable is bound to <code>NIL</code>. See also <code><a
    341 href="refN.html#not/1">not/1</a></code>.
    342 
    343 <pre><code>
    344 : (? @X NIL (nil @X))
    345  @X=NIL
    346 -> NIL
    347 </code></pre>
    348 
    349 <dt><a name="noLint"><code>(noLint 'sym)</code></a>
    350 <dt><code>(noLint 'sym|(sym . cls) 'sym2)</code>
    351 <dd>(Debug mode only) Excludes the check for a function definition of
    352 <code>sym</code> (in the first form), or for variable binding and usage of
    353 <code>sym2</code> in the function definition, file contents or method body of
    354 <code>sym</code> (second form), during calls to <code><a
    355 href="refL.html#lint">lint</a></code>. See also <code><a
    356 href="refL.html#lintAll">lintAll</a></code>.
    357 
    358 <pre><code>
    359 : (de foo ()
    360    (bar FreeVariable) )
    361 -> foo
    362 : (lint 'foo)
    363 -> ((def bar) (bnd FreeVariable))
    364 : (noLint 'bar)
    365 -> bar
    366 : (noLint 'foo 'FreeVariable)
    367 -> (foo . FreeVariable)
    368 : (lint 'foo)
    369 -> NIL
    370 </code></pre>
    371 
    372 <dt><a name="nond"><code>(nond ('any1 . prg1) ('any2 . prg2) ..) -> any</code></a>
    373 <dd>Negated ("non-cond") multi-way conditional: If any of the <code>anyN</code>
    374 conditions evaluates to <code>NIL</code>, <code>prgN</code> is executed and the
    375 result returned. Otherwise (all conditions evaluate to non-<code>NIL</code>),
    376 <code>NIL</code> is returned. See also <code><a
    377 href="refC.html#cond">cond</a></code>, <code><a
    378 href="refI.html#ifn">ifn</a></code> and <code><a
    379 href="refU.html#unless">unless</a></code>.
    380 
    381 <pre><code>
    382 : (nond
    383    ((= 3 3) (println 1))
    384    ((= 3 4) (println 2))
    385    (NIL (println 3)) )
    386 2
    387 -> 2
    388 </code></pre>
    389 
    390 <dt><a name="nor"><code>(nor 'any ..) -> flg</code></a>
    391 <dd>Logical NOR. The expressions <code>any</code> are evaluated from left to
    392 right. If a non-<code>NIL</code> value is encountered, <code>NIL</code> is
    393 returned immediately. Else <code>T</code> is returned. <code>(nor ..)</code> is
    394 equivalent to <code>(not (or ..))</code>.
    395 
    396 <pre><code>
    397 : (nor (lt0 7) (= 3 4))
    398 -> T
    399 </code></pre>
    400 
    401 <dt><a name="not"><code>(not 'any) -> flg</code></a>
    402 <dd>Logical negation. Returns <code>T</code> if <code>any</code> evaluates to
    403 <code>NIL</code>.
    404 
    405 <pre><code>
    406 : (not (== 'a 'a))
    407 -> NIL
    408 : (not (get 'a 'a))
    409 -> T
    410 </code></pre>
    411 
    412 <dt><a name="not/1"><code>not/1</code></a>
    413 <dd><a href="ref.html#pilog">Pilog</a> predicate that succeeds if and only if
    414 the goal cannot be proven. See also <code><a
    415 href="refN.html#nil/1">nil/1</a></code>, <code><a
    416 href="refT.html#true/0">true/0</a></code> and <code><a
    417 href="refF.html#fail/0">fail/0</a></code>.
    418 
    419 <pre><code>
    420 : (? (equal 3 4))
    421 -> NIL
    422 : (? (not (equal 3 4)))
    423 -> T
    424 </code></pre>
    425 
    426 <dt><a name="nth"><code>(nth 'lst 'cnt ..) -> lst</code></a>
    427 <dd>Returns the tail of <code>lst</code> starting from the <code>cnt</code>'th
    428 element of <code>lst</code>. Successive <code>cnt</code> arguments operate on
    429 the results in the same way. <code>(nth 'lst 2)</code> is equivalent to
    430 <code>(cdr 'lst)</code>. See also <code><a href="refG.html#get">get</a></code>.
    431 
    432 <pre><code>
    433 : (nth '(a b c d) 2)
    434 -> (b c d)
    435 : (nth '(a (b c) d) 2 2)
    436 -> (c)
    437 : (cdadr '(a (b c) d))
    438 -> (c)
    439 </code></pre>
    440 
    441 <dt><a name="num?"><code>(num? 'any) -> num | NIL</code></a>
    442 <dd>Returns <code>any</code> when the argument <code>any</code> is a number,
    443 otherwise <code>NIL</code>.
    444 
    445 <pre><code>
    446 : (num? 123)
    447 -> 123
    448 : (num? (1 2 3))
    449 -> NIL
    450 </code></pre>
    451 
    452 </dl>
    453 
    454 </body>
    455 </html>