SICPy_0 - nus-cs4215/x-slang-t1-xz-jj GitHub Wiki

SICPy §0

SICPy §0 is a very small programming language, designed for the first two lectures of CS4215, adapted from the Soruce programming language which was designed for the textbook Structure and Interpretation of Computer Programs, JavaScript Adaptation (SICP JS).

What names are predeclared in SICPy §0?

None.

What can you do in SICPy §0?

Literal values

Literal values are simple expressions that directly evaluate to values. These include numbers in the usual decimal notation, the two boolean values True and False. More on literal values in section 1.1 The Elements of Programming of the textbook.

Arithmetic expressions/ operation

Fairly straightforward, an example would be 1 + 1 * 2.

Conditional expressions

Within expressions, you can let a predicate determine whether a consequent expression gets evaluated or an alternative expression. This is done by writing, for example

3 if 1==1 else 4

Boolean operators

Boolean operators in SICPy have a special meaning. Usually, an operator combination evaluates all its arguments and then applies the operation to which the operator refers. For example, (2 * 3) + (4 * 5) evaluates 2 * 3 and 4 * 5 first, before the addition is carried out. H owever, the operator and works differently. An expression e1 and e2 should be seen as an abbreviation for e2 if e1 else false. The expression e2 only gets evaluated if e1 evaluates to true. The behaviour of or is similar: e1 or e2 should be seen as an abbreviation for true if e1 else e2. More on these two boolean operators in textbook section 1.1.6 Conditional Expressions and Predicates.

Sequences

One can write multiple statements in a row. In the REPL ("Read-Eval-Print-Loop") of a SICPy implementation, you can write

1+1
2+2

The statements in such a sequence are evaluated in the given order. The result of evaluating the sequence is the result of evaluating the last statement in the sequence, in this case 2+2. Read more about sequences in section 1.1.2 Naming and the Environment of the textbook.

Specifications

Refer to this document for the specifications.