aboutsummaryrefslogtreecommitdiff
path: root/TUTORIAL.md
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-04 23:50:46 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-04 23:50:46 +0300
commitfdae943090463526423f5e43e72cd2f0e8147a1b (patch)
tree5a7212555d8511df16fe6bbcc54b863ec9463b46 /TUTORIAL.md
parent36d2818d39e61b752923e253f8455f50510cb428 (diff)
downloadmyslip-fdae943090463526423f5e43e72cd2f0e8147a1b.tar.gz
myslip-fdae943090463526423f5e43e72cd2f0e8147a1b.zip
Added repl and some documentation. Improved error messages. Removed dead code.
* Removed same_variant in parse::parsetree * Added SExp::multistep (for use of the repl) Improved error messages: * Added parenthesis around types * Changed how errors propagate inferring generics: added the error variant ArgumentsDontMatchGeneric, implemented the displaying of it, added tests for it. * Had to change some tests to match for the new changes
Diffstat (limited to 'TUTORIAL.md')
-rw-r--r--TUTORIAL.md84
1 files changed, 84 insertions, 0 deletions
diff --git a/TUTORIAL.md b/TUTORIAL.md
new file mode 100644
index 0000000..7389d55
--- /dev/null
+++ b/TUTORIAL.md
@@ -0,0 +1,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