swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 1 | Lisp Standard Library |
| 2 | ===================== |
| 3 | |
| 4 | This provides documentation for every built-in function in the Lisp standard |
| 5 | library. It is not auto-generated, please update this documentation if you |
| 6 | change the API in any way. |
| 7 | |
| 8 | In general every user-facing API in the standard library should be documented |
| 9 | here. |
| 10 | |
swissChili | 5500f70 | 2021-06-30 22:11:17 -0700 | [diff] [blame] | 11 | Functions |
| 12 | --------- |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 13 | |
| 14 | .. function:: (if condition true-condition [false-condition]) |
| 15 | |
| 16 | Evaluates ``condition``, if it is truthy (non-``nil``) ``true-condition`` is |
| 17 | evaluated. Otherwise ``false-condition`` is evaluated. If |
| 18 | ``false-condition`` is not provided, ``if`` will evaluate to ``nil``. |
| 19 | |
| 20 | .. function:: (let1 (variable binding) & body) |
| 21 | |
| 22 | Evaluates ``binding`` and binds it to ``variable``, then evaluates ``body``. |
| 23 | After ``body`` is evaluated ``variable`` is unbound. |
| 24 | |
| 25 | .. code-block:: lisp |
| 26 | |
| 27 | (let1 (greeting (greet "John")) |
| 28 | (do-something greeting) |
| 29 | (print greeting)) |
| 30 | ; greeting is no longer bound |
| 31 | |
| 32 | .. function:: (gc) |
| 33 | |
| 34 | Force the garbage collector (GC) to run. |
| 35 | |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 36 | .. function:: (car pair) |
| 37 | |
| 38 | Return the first item in ``pair``. |
| 39 | |
| 40 | .. function:: (cdr pair) |
| 41 | |
| 42 | Return the second (last) item in ``pair``. |
| 43 | |
| 44 | .. function:: (cons a b) |
| 45 | |
| 46 | Return a cons-pair containing ``a`` and ``b``. |
| 47 | |
| 48 | .. function:: (print val) |
| 49 | |
| 50 | Print out ``val`` to standard output. This will not be formatted as an |
swissChili | 5500f70 | 2021-06-30 22:11:17 -0700 | [diff] [blame] | 51 | s-expression, but in a manner more similar to the internal representation. |
| 52 | |
| 53 | .. function:: (list & items) |
| 54 | |
| 55 | Returns a cons-list of items. |
| 56 | |
| 57 | .. function:: (quote form) |
| 58 | |
| 59 | Returns form without evaluating it. |
| 60 | |
| 61 | .. code-block:: lisp |
| 62 | '(cons a b) |
| 63 | |
| 64 | '(cons a b) |
| 65 | ; or |
| 66 | (quote cons a b) |
| 67 | ; is the same as |
| 68 | (list 'cons 'a 'b) |