aboutsummaryrefslogtreecommitdiff
path: root/TUTORIAL.md
blob: 7389d55594508906e9c2443021d5a2cbb9c01b07 (plain)
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


Tutorial
========

This tutorial consists of a language tour
and a set of exercises, in the order of
mentioning.


Tour
----


**Arithmetic operations**

Addition, multiplication, subtraction and division
are supported with +, *, - and / respectively.
```console
> (+ 1 1)
2 : Int
> (* 2 3)
6 : Int
> (- 5 4)
1 : Int
> (/ 4 2)
2 : Int
```

Decimals are truncated in division:
```console
> (/ 5 2)
2 : Int
```


**Lists**

Lists in myslip correspond to what is known as tuples in many
other programming languages. This difference exists because
myslip is a list processor, and not using this underlying
construct of the language would be odd.

In principle,
```myslip
(1 2 3 4 5)
```
is a valid list, but it is evaluated by the interpreter,
which assumes that the first term, `1`, is an operator.
That's why constructing a list requires the operator
`quote`:
```console
> quote
quote : (T -> T)
> (quote 1 2 3 4 5)
(quote 1 2 3 4 5) : (Int Int Int Int Int)
```

As hinted above, `quote` is typewise the identity function.
Behaviorally it does though simplify sub-expressions.
```console
> (quote (+ 1 1) (+ 2 2))
(quote 2 4) : (Int Int)
```

The elements of a list can of course be of different types:
```console
> (quote + 0 (quote 1 2))
(quote + 0 (quote 1 2)) : (((Int Int) -> Int) Int (Int Int))
```

TODO: List destructuring


**Understanding error messages**
TODO: div zero
TODO: unclosed parenthesis
TODO: type errors


Exercises
---------

TODO