Update SPECIFICATION.MD

This commit is contained in:
zongor 2024-07-20 13:48:42 -04:00
parent 3ac54394de
commit 6c83ee3614
1 changed files with 49 additions and 54 deletions

View File

@ -174,12 +174,12 @@ So as you can see each type includes some extra information, its type, if it has
``` ```
frm «form_token» impls «this_form», «that_form» { frm «form_token» impls «this_form», «that_form» {
version : [0, 0, 1] ! version number for auto saving to a database or whatnot version; ! version number for auto saving to a database or whatnot
migrate : <> ! this is to migrate from the previous version to new, in case of interface changes, or None migrate; ! this is to migrate from the previous version to new, in case of interface changes, or None
dimensions : 0 ! this returns how many dimensions it can exist in, 0th means non drawable, 2 means 2D GUI usually, 3 means 3D object, and >3 is somthing you will have to implement yourself, e.g. miegakure dimensions; ! this returns how many dimensions it can exist in, 0th means non drawable, 2 means 2D GUI usually, 3 means 3D object, and >3 is somthing you will have to implement yourself, e.g. miegakure
unit : <> ! this is for the unit/measures system unit; ! this is for the unit/measures system
display : <> ! some kind of UI form or None display; ! some kind of UI form or None
position : <> ! a position in space or None position; ! a position in space or None
} }
``` ```
@ -209,37 +209,6 @@ matching `""` for string
strings are always utf8, other formats will need to be done manually strings are always utf8, other formats will need to be done manually
## measurement
- forms
- time
- unit
- seconds (s)
- subforms
- date
- Default is ISO 8601
- length
- unit
- metre (m)
- subforms
- angle
- radian (rad)
- mass
- unit
- kilogram (kg)
- electric current
- unit
- ampere (a)
- temperature
- unit
- kelvin (K)
- amount of substance
- unit
- mol (mol)
- luminous intensity
- unit
- candela (candela)
## logical ## logical
`bool` `bool`
@ -250,38 +219,33 @@ Also follows the style boolean 'c' rules of nonzero / zero, but the interpreter
## null values ## null values
### *zwl* does not have null, it stole some monads from Rust, Haskell, and the like *zwl* does not have null, because each value can have an error on it.
If you are coming from haskell, a 'Just' is `< some value >` and a 'None' is `<>`, note 'None' is also an error error is a form which describes an error that occurred, it is similar to the Go programming language and is returned as a monad like the maybe monad above and is unwrapped in a similar way, take a look at the tunnel section for an example
Like in Rust you have `unwrap` and `unwrap_or` and the like, you use `?` and `??`
``` ```
1| i32 a = <3>; ! this can also be writen `i32 a = just(3);` 1| i32 a = 3; ! this would be similar to the follwing in Rust: `let a: Result<i32, &'static str> = Ok(3);`
2| i32 b = <>; ! this can also be written `i32 b = none;` 2| i32 b; ! or like in Rust: `let b: Result<i32, &'static str>;`
3| 3|
4| i32 x ?= a; ! this will set x to 3 4| i32 x = a; ! this will set x to 3
5| i32 y ?= b; ! this will set y to an error 5| i32 y = b; ! this will set the error part of y to an undefined error because we tried setting a undefined variable to another variable, imagine in Rust: `let y: Result<i32, &'static str> = Err("undefined");`
6| i32 z ?= b ?= 1; ! this will return an error from b, then unwrap the error and set y = 1; 6| i32 z = b ? 1; ! this will check if b has an error and since it does it will set y = 1;
7| 7|
8| print("$x $y $z\n") ! prints 3, "error: failed to unwrap a 'none' on line 5", 1 8| print("$x $y $z\n") ! prints 3, "error: failed to unwrap a 'none' on line 5", 1
``` ```
additionally, a None will be evaluated as "false" and Just as "true" in a boolean check additionally, if a value has an error it will evaluate as "false" and Just as "true" in a boolean check, unless you are explicitly checking for an error
## error
error is a form which describes an error that occurred, it is similar to the Go programming language and is returned as a monad like the maybe monad above and is unwrapped in a similar way, take a look at the tunnel section for an example
### panic ### panic
calling panic on a variable that has an error will halt execution of the node that is running. calling panic on a variable that has an error will halt execution of the node that is running.
``` ```
i32 n = <>; ! this can also be written `i32 b = none;` i32 n;
i32 e ?= n; ! this will be an error i32 e = n; ! this will set e's error that we tried setting n to undefined.
if (e.err) { ! since the 'none' error is zero this will only branch if an error exists on the variable err (e) { ! we can check if there is an error by using the `err` keyword in the same way as an `if`
panic(e); panic(e); ! panic will halt exectution of the task and pass a message what the error was to all the other tasks listening.
} }
``` ```
@ -591,3 +555,34 @@ test some_test {
``` ```
## Measurement
- forms
- time
- unit
- seconds (s)
- subforms
- date
- Default is ISO 8601
- length
- unit
- metre (m)
- subforms
- angle
- radian (rad)
- mass
- unit
- kilogram (kg)
- electric current
- unit
- ampere (a)
- temperature
- unit
- kelvin (K)
- amount of substance
- unit
- mol (mol)
- luminous intensity
- unit
- candela (candela)