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 | |
| 11 | Built-in "functions" |
| 12 | -------------------- |
| 13 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 14 | .. function:: (defun function-name (arg1 ... argN) & body) |
| 15 | |
| 16 | Define a function ``function-name`` that takes N arguments with names |
| 17 | ``arg1`` ... ``argN``. ``body`` is evaluated in order, with the whole |
| 18 | function evaluating to the last expression. |
| 19 | |
| 20 | .. code-block:: lisp |
| 21 | |
| 22 | (defun greet (name) |
| 23 | (string-concat "Hello, " name)) |
| 24 | ; string-concat isn't even implemented yet, but you get the picture. |
| 25 | |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 26 | .. function:: (if condition true-condition [false-condition]) |
| 27 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 28 | Evaluates ``condition``, if it is truthy (non-``nil``) ``true-condition`` is |
| 29 | evaluated. Otherwise ``false-condition`` is evaluated. If |
| 30 | ``false-condition`` is not provided and ``condition`` is ``nil``, ``if`` |
| 31 | will evaluate to ``nil``. |
| 32 | |
| 33 | .. code-block:: lisp |
| 34 | |
| 35 | (print (if (= 2 3) |
| 36 | "2 = 3" |
| 37 | "2 /= 3")) |
| 38 | ; 2 /= 3 |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 39 | |
| 40 | .. function:: (let1 (variable binding) & body) |
| 41 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 42 | Evaluates ``binding`` and binds it to ``variable``, then evaluates ``body``. |
| 43 | After ``body`` is evaluated ``variable`` is unbound. |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 44 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 45 | .. code-block:: lisp |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 46 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 47 | (let1 (greeting (greet "John")) |
| 48 | (do-something greeting) |
| 49 | (print greeting)) |
| 50 | ; greeting is no longer bound |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 51 | |
| 52 | .. function:: (gc) |
| 53 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 54 | Force the garbage collector (GC) to run. |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 55 | |
| 56 | Functions |
| 57 | --------- |
| 58 | |
| 59 | .. function:: (car pair) |
| 60 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 61 | Return the first item in ``pair``. |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 62 | |
| 63 | .. function:: (cdr pair) |
| 64 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 65 | Return the second (last) item in ``pair``. |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 66 | |
| 67 | .. function:: (cons a b) |
| 68 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 69 | Return a cons-pair containing ``a`` and ``b``. |
swissChili | e9fec8b | 2021-06-22 13:59:33 -0700 | [diff] [blame] | 70 | |
| 71 | .. function:: (print val) |
| 72 | |
swissChili | c3b56c1 | 2021-07-02 20:52:09 -0700 | [diff] [blame^] | 73 | Print out ``val`` to standard output. This will not be formatted as an |
| 74 | s-expression, but in a manner more similar to the internal representation. |
| 75 | |