aboutsummaryrefslogtreecommitdiff
path: root/TUTORIAL.md
diff options
context:
space:
mode:
Diffstat (limited to 'TUTORIAL.md')
-rw-r--r--TUTORIAL.md54
1 files changed, 42 insertions, 12 deletions
diff --git a/TUTORIAL.md b/TUTORIAL.md
index 2f4edf8..0f6a21a 100644
--- a/TUTORIAL.md
+++ b/TUTORIAL.md
@@ -146,7 +146,7 @@ others.
++ saved
> (++ 1)
2 : Int
-> (let between (fn (a b c) (Int Int Int) bool (and (< b c) (> b a))))
+> (let between (fn (a b c) (Int Int Int) Bool (and (< b c) (> b a))))
between saved
> (between 1 2 3)
true : Bool
@@ -264,22 +264,13 @@ true : Bool
Pattern matching can be done on vectors too.
Just remember that the rest pattern `..r` needs to be at
-the end of the pattern — not at the end of a subpattern.
+the end of the whole pattern.
```console
> (let myvec (vector 1 2 3 4 5))
myvec saved
> (case myvec ((head ..tail) head) (_ 0))
1 : Int
```
-Here's a failing example of trying to put a rest pattern at
-the end of a subpattern:
-```console
-> (case (quote myvec false) (((head ..tail) false) head) (_ 0))
-Type error: unbound generic type 'T' in 'T'
-```
-Try extracting the vector first through one pattern and
-then pattern matching on the extracted vector for your
-desired behaviour.
General recursion
@@ -305,8 +296,47 @@ The factorial function could be implemented as such:
))
```
+Printing
+--------
+
+This is quite a useless feature as the repl already
+echoes all results. But if you fancy, you can print
+anything using the `print` operator, which is
+behaviorally equivalent to Nil as long as its argument
+is valid myslip. For example, with the standard library
+enabled:
+```console
+> (let x 1)
+x saved
+> (print 1)
+() : Nil
+> (print sum)
+(fn vec (Vector (Int ...)) Int (case vec ((h ..t) + h ((fix (fn sum' ((Vector (Int ...)) -> Int) ((Vector (Int ...)) -> Int) (fn vec (Vector (Int ...)) Int (case vec ((h ..t) + h (sum' t)) (_ 0))))) t)) (_ 0)))
+() : Nil
+```
+
Exercises
=========
-TODO
+These exercises are meant to make you familiar with the
+language. The solutions can be found in the `solutions`
+folder under the project root.
+
+Exercise 1: Fibonacci sequence
+------------------------------
+
+Write a function that calculates the n:th fibonacci number.
+
+This should make you familiar with function definitions and
+fixed point recursion.
+
+Example of desired behaviour:
+```console
+> (fibonacci 1)
+0 : Int
+> (let n 10)
+n saved
+> (fibonacci n)
+34 : Int
+```