aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TUTORIAL.md43
1 files changed, 43 insertions, 0 deletions
diff --git a/TUTORIAL.md b/TUTORIAL.md
index ba6b8a1..df2eea7 100644
--- a/TUTORIAL.md
+++ b/TUTORIAL.md
@@ -82,6 +82,12 @@ form `(if [condition] [iftrue] [iffalse])`:
> (if false 1 0)
0 : Int
```
+Note though that they are not short-circuiting as their
+arguments are evaluated before passing to the operator as
+with all functions defined in myslip. Implementing a
+short-circuiting version would be possible if an 'unquoting'
+operator was added. If you wish short-circuiting behavior,
+use case directly instead.
Integer comparisons
@@ -416,6 +422,43 @@ print twice looks horrible.
That looks better!
+Loops
+=====
+
+Loops are quite worthless in a functional language, but I
+might get points for them. The standard library provides the
+functions `repeat` and `map-i->i`.
+
+The former one has the syntax
+`(repeat [operation] [number of times])` which quite
+intuitively repeats the given operation the given number of
+times. The operation should be a function that takes an
+integer as an argument and returns Nil, so this function is
+quite useless for anything but printing.
+```console
+> (repeat (fn x Int Nil (print x)) 10)
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+() : Nil
+```
+
+The latter has the syntax `(map-i->i [vector] [operation])`
+where only vectors of integers and operations from integers
+to integers are supported. More general mapping functions
+would require more sophisticated generics.
+
+The standard library also provides a similar function for
+filtering on vectors of integers.
+
+
Exercises
=========