From fdae943090463526423f5e43e72cd2f0e8147a1b Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Mon, 4 Aug 2025 23:50:46 +0300 Subject: 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 --- TUTORIAL.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 TUTORIAL.md (limited to 'TUTORIAL.md') 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 -- cgit v1.2.3