diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-04 11:55:34 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-04 11:55:34 +0100 |
| commit | 635ea8b5c5c16be2780e6aa1fdb7baa8c6d46783 (patch) | |
| tree | 8e60fa754eeac150414fb6ef35a401324ff34073 /SPEC.md | |
| parent | a778dbd8e81ac02db4171b68fc2ac59fc0eb344d (diff) | |
| download | sylt-635ea8b5c5c16be2780e6aa1fdb7baa8c6d46783.tar.gz | |
add more to the spec
Diffstat (limited to 'SPEC.md')
| -rw-r--r-- | SPEC.md | 51 |
1 files changed, 42 insertions, 9 deletions
@@ -29,6 +29,10 @@ d := fn a: int -> int { ret a + 1 } +// Constant +a :: 1 +a = 2 // This is illegal + // Destructuring a tuple is allowed, after the definiton // e = 1, f = 2, g = 3. // If the number of variables doesn't match the length @@ -91,16 +95,45 @@ for { break; } -// 'After-doer' -// Any form of code can be placed -// after an arrow, this will be run AFTER -// each cycle. -for -> { - -} -> { - print(1) - break; +``` + +### Functions +All functions are values. +```sylt +// Declare and create the function +f :: fn { + print "A" } +// Semantically equivalent +f() +f! +// Declare and create the function +f :: fn a:int -> int { + print a + ret a + 1 +} +// Semantically equivalent +f 1 +f(1) + +// Closures exist +q := 1 +g :: fn -> int { + ret q // Here the variable 'q' is captured +} +q = 2 +print g! // prints 2 + +// Supports heigher order functions +h :: fn -> fn -> int { + ret fn -> int { ret 2 } +} +print h()() // prints 2 ``` +### Special syntax +```sylt +<!> // The unreachable statement, it should never be executed +1 <=> 1 // Asserts equality, so the program crashes if 1 != 1 +``` |
