From 83b150097303ee7c8c9913b35cf863c7db955a86 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 13 Apr 2024 15:46:22 +0100 Subject: Typos, clarifications --- language.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'language.md') diff --git a/language.md b/language.md index 63b2b1d..0957480 100644 --- a/language.md +++ b/language.md @@ -151,7 +151,7 @@ Logic operators result on a boolean type. | Type | Description | Samples | | --- | --- | --- | -| ([parameters]) -> [return] | function | `(a: u8) -> u8 { return a + 1; }` | +| ([parameters]) -> [return] | function | `(a: u8): u8 { return a + 1; }` | | ([parameters]) | function (no return value) | `() { return; }` | Functions can be declared with `def` when they have a name, or as anonymous using the lambda syntax. @@ -176,7 +176,7 @@ Anonymous function: Function are higher order functions: ``` -def apply(fn: (u8) -> u8, a: u8, b: u8): u8 { +def apply(fn: (u8): u8, a: u8, b: u8): u8 { return fn(a, b); } @@ -189,7 +189,7 @@ apply((a: u8, b: u8): u8 { 2, 8); # 10 # lambdas can be assigned to variables -var double: (u8) -> u8 = (a: u8): u8 { +var double: (u8): u8 = (a: u8): u8 { return a + a; }; @@ -198,7 +198,7 @@ double(10); # 20 Anonymous functions can only access local variables (closures aren't supported): ``` -def closure(a: u8): () -> u8 { +def closure(a: u8): (): u8 { return (): u8 { return a; # invalid return, undefined a }; @@ -229,7 +229,7 @@ Using a *nil* reference will result in a runtime error. ``` # fn doesn't hold a reference -var fn: (u8) -> u8 = nil; +var fn: (u8): u8 = nil; fn(10); # runtime error ``` @@ -250,7 +250,7 @@ def A { var ( n: u8 = 100, m: bool = false, - dec: (u8) -> u8 = nil + dec: (u8): u8 = nil ); # it is possible to define functions local @@ -289,6 +289,8 @@ var c: A = nil; Recursive structures are not supported and local structures can't be used as return value in a function. +XXX: how do we implement e.g. linked lists? + ### Arrays Arrays are zero based and are supported for all types. @@ -346,7 +348,7 @@ Built-in functions: | Function | Description | Samples | | --- | --- | --- | | len | get the length of an array as u16 | `len(arr); # 5` | -| incbin | load a binary file as []u8 | `const f: []u8 = incbin("file.bin");` | +| incbin | include a binary file as []u8 | `const f: []u8 = incbin("file.bin");` | ### Strings -- cgit v1.2.3