aboutsummaryrefslogtreecommitdiff
path: root/TUTORIAL.md
blob: 9494859e79ecdb52614588ad3bc36cc35934fb94 (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
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
117
118
119
120
121
122
123
124


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
```


**Booleans**

Myslip supports booleans and `and`, `or`, `xor` and `not`
for their comparisons.
```console
> true
true : Bool
> false
false : Bool
> (and true true)
true : Bool
> (or true false)
true : Bool
> (xor true true)
false : Bool
> (not true)
false : Bool
```


**Integer comparisons**

To generate booleans from integers, some basic and quite
self-explanatory operators are supplied.
```console
> (>  2 1)
true : Bool
> (<  1 2)
true : Bool
> (>= 1 1)
true : Bool
> (<= 1 1)
true : Bool
> (=  1 1)
true : Bool
> (!= 1 1)
false : Bool
```


**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