blob: 261f3882da55ac5d33e5bd1495981940dff4bffa [file] [log] [blame]
swissChilie9fec8b2021-06-22 13:59:33 -07001Lisp Standard Library
2=====================
3
4This provides documentation for every built-in function in the Lisp standard
5library. It is not auto-generated, please update this documentation if you
6change the API in any way.
7
8In general every user-facing API in the standard library should be documented
9here.
10
11Built-in "functions"
12--------------------
13
swissChilic3b56c12021-07-02 20:52:09 -070014.. 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
swissChilie9fec8b2021-06-22 13:59:33 -070026.. function:: (if condition true-condition [false-condition])
27
swissChilic3b56c12021-07-02 20:52:09 -070028 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
swissChilie9fec8b2021-06-22 13:59:33 -070039
40.. function:: (let1 (variable binding) & body)
41
swissChilic3b56c12021-07-02 20:52:09 -070042 Evaluates ``binding`` and binds it to ``variable``, then evaluates ``body``.
43 After ``body`` is evaluated ``variable`` is unbound.
swissChilie9fec8b2021-06-22 13:59:33 -070044
swissChilic3b56c12021-07-02 20:52:09 -070045 .. code-block:: lisp
swissChilie9fec8b2021-06-22 13:59:33 -070046
swissChilic3b56c12021-07-02 20:52:09 -070047 (let1 (greeting (greet "John"))
48 (do-something greeting)
49 (print greeting))
50 ; greeting is no longer bound
swissChilie9fec8b2021-06-22 13:59:33 -070051
52.. function:: (gc)
53
swissChilic3b56c12021-07-02 20:52:09 -070054 Force the garbage collector (GC) to run.
swissChilie9fec8b2021-06-22 13:59:33 -070055
56Functions
57---------
58
59.. function:: (car pair)
60
swissChilic3b56c12021-07-02 20:52:09 -070061 Return the first item in ``pair``.
swissChilie9fec8b2021-06-22 13:59:33 -070062
63.. function:: (cdr pair)
64
swissChilic3b56c12021-07-02 20:52:09 -070065 Return the second (last) item in ``pair``.
swissChilie9fec8b2021-06-22 13:59:33 -070066
67.. function:: (cons a b)
68
swissChilic3b56c12021-07-02 20:52:09 -070069 Return a cons-pair containing ``a`` and ``b``.
swissChilie9fec8b2021-06-22 13:59:33 -070070
71.. function:: (print val)
72
swissChilic3b56c12021-07-02 20:52:09 -070073 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