Skip to content

Commit 7ffc79e

Browse files
committed
fixed Lisra syntax and semantics table
1 parent b58da98 commit 7ffc79e

File tree

1 file changed

+9
-46
lines changed

1 file changed

+9
-46
lines changed

courses/Recipes/Languages/Lisra/Lisra.md

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -36,52 +36,15 @@ The Lisp variant to be implemented is the following subset of the [Scheme](http:
3636

3737
| Form | Syntax | Semantics and Example |
3838
| --- | --- | --- |
39-
| [variable reference](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.1) |
40-
| _var_ |
41-
| A symbol is interpreted as a variable name; |
42-
its value is the variable's |
43-
value. Example: `x` |
44-
| [constant literal](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.2) |
45-
| _number_ |
46-
| A number evaluates to itself. Example: `12` |
47-
| [quotation](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.2) |
48-
| `(quote exp)` |
49-
| Return the _exp_ literally; do not evaluate it. Example: |
50-
`(quote (a b c)) =>; (a b c)` |
51-
| [conditional](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.5) |
52-
| `(if _test conseq alt_)` |
53-
| Evaluate _test_; if true, |
54-
evaluate and return _conseq_; otherwise evaluate and return |
55-
_alt_. <br />Example: `(if (< 10 20) (+ 1 1) (+ 3 3)) => 2` |
56-
| [assignment](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.6) |
57-
| `(set! _var exp_)` |
58-
| Evaluate _exp_ and assign that value to |
59-
_var_, which must have been previously defined (with a |
60-
`define` or as a parameter to an enclosing procedure). |
61-
Example: `(set! x2 (* x x))` |
62-
| [definition](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-8.html#%_sec_5.2) |
63-
| `(define var exp)` |
64-
| Define a new variable in the innermost environment and give it |
65-
the value of evaluating the expression _exp_. |
66-
Examples: `(define r 3)` or `(define square (lambda (x) (* x x)))` |
67-
| [procedure](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.4) |
68-
| `(lambda (_var..._) exp)` |
69-
| Create a procedure |
70-
with parameter(s) named _var..._ and the expression as the body. |
71-
Example: `(lambda (r) (* r r))` |
72-
| [sequencing](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.2.3) |
73-
| `(begin _exp..._)` |
74-
| Evaluate each of the expressions in left-to-right order, and return the final value. |
75-
Example: `(begin (set! x 1) (set! x (+ x 1)) (* x 2)) => 4 |
76-
| [procedure call](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.3) |
77-
| `(_proc exp..._)` |
78-
| If _proc_ is |
79-
anything other than one of the symbols `if`, `set!`, `define`, |
80-
`lambda`, `begin`, or `quote` then it is treated as a procedure. It is |
81-
evaluated using the same rules defined here. All the expressions |
82-
are evaluated as well, and then the procedure is called with the list |
83-
of expressions as arguments. |
84-
Example: <`(square 12) => 144 |
39+
| [variable reference](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.1) | _var_ | A symbol is interpreted as a variable name; its value is the variable's value. Example: `x` |
40+
| [constant literal](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.2) | _number_ | A number evaluates to itself. Example: `12` |
41+
| [quotation](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.2) | `(quote exp)` | Return the _exp_ literally; do not evaluate it. Example: `(quote (a b c)) =>; (a b c)` |
42+
| [conditional](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.5) | `(if _test conseq alt_)` | Evaluate _test_; if true, evaluate and return _conseq_; otherwise evaluate and return _alt_. Example: `(if (< 10 20) (+ 1 1) (+ 3 3)) => 2` |
43+
| [assignment](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.6) | `(set! _var exp_)` | Evaluate _exp_ and assign that value to _var_, which must have been previously defined (with a `define` or as a parameter to an enclosing procedure). | Example: `(set! x2 (* x x))` |
44+
| [definition](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-8.html#%_sec_5.2) | `(define var exp)` | Define a new variable in the innermost environment and give it the value of evaluating the expression _exp_. Examples: `(define r 3)` or `(define square (lambda (x) (* x x)))` |
45+
| [procedure](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.4) | `(lambda (_var..._) exp)` | Create a procedure with parameter(s) named _var..._ and the expression as the body. Example: `(lambda (r) (* r r))` |
46+
| [sequencing](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.2.3) | `(begin _exp..._)` | Evaluate each of the expressions in left-to-right order, and return the final value. Example: `(begin (set! x 1) (set! x (+ x 1)) (* x 2)) => 4 |
47+
| [procedure call](http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.3) | `(_proc exp..._)` | If _proc_ is anything other than one of the symbols `if`, `set!`, `define`, `lambda`, `begin`, or `quote` then it is treated as a procedure. It is evaluated using the same rules defined here. All the expressions are evaluated as well, and then the procedure is called with the list of expressions as arguments. Example: <`(square 12) => 144 |
8548

8649

8750
In this table, _var_ must be a symbol--an identifier such as x or square--and number must be an integer number,

0 commit comments

Comments
 (0)