aboutsummaryrefslogtreecommitdiff
path: root/docs/syntax.rst
blob: 71bd35b377d8c139e29d5202257d639877dc8b69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Builtin syntaxes
================

This implementation includes minimal number of builtin syntaxes. All other
constructs should be defined as user defined syntaxes in Lisp itself.

In following examples, lines starting with ``>`` represent characters
provided to input stream. Lines without starting ``>`` character represent
evaluation results written to output stream.

Available builtin syntaxes are:

    * `lambda`

        Definition of new user defined function.

        Examples::

            > ((lambda x x) 1 2 3)
            (1 2 3)

            > ((lambda (x) x) 1)
            1

            > ((lambda (x . y) y) 1 2 3)
            (2 3)

    * `syntax`

        Definition of new user defined syntax.

        Examples::

            > ((syntax x x) (lambda x x) 1 2 3)
            (1 2 3)

    * `define`

        Add new symbol binding to current context.

        Examples::

            > (define xyz 42)
            > xyz
            42

    * `set!`

        Change previously defined context entry.

        Examples::

            > (define xyz 42)
            > xyz
            42
            > (set! xyz 24)
            > xyz
            24

    * `begin`

        Evaluate multiple expressions and return result of last expression
        evaluation.

        Examples::

            > (begin 1 2 3)
            3

    * `quote`

        Evaluates to provided argument.

        Examples::

            > (quote (1 2 3))
            (1 2 3)

            > '(3 2 1)
            (3 2 1)

    * `if`

        If first argument evaluates to `thruthy` value, `if` syntax returns
        result of second argument evaluation. If first argument evaluates to
        `falsy` value, result of third argument evaluation is returned or
        ``()`` if third argument is not available.

        `Falsy` values are ``0``, ``()``, ``""`` and empty symbol.

        `Thruthy` values are all that are not `falsy`.

        Examples::

            > (if 0 1 2)
            2

            > (if "0" 1 2)
            1


Source code
-----------

syntax.h
''''''''

.. literalinclude:: ../src_c/syntax.h
    :language: c


syntax.c
''''''''

.. literalinclude:: ../src_c/syntax.c
    :language: c