| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'content/fate_v1/computations')
| -rw-r--r-- | content/fate_v1/computations/_index.md | 138 | ||||
| -rw-r--r-- | content/fate_v1/computations/collections/_index.md | 98 | ||||
| -rw-r--r-- | content/fate_v1/computations/conditionals/_index.md | 54 | ||||
| -rw-r--r-- | content/fate_v1/computations/cons/_index.md | 22 | ||||
| -rw-r--r-- | content/fate_v1/computations/lambda_functions/_index.md | 30 | ||||
| -rw-r--r-- | content/fate_v1/computations/references/_index.md | 18 | ||||
| -rw-r--r-- | content/fate_v1/computations/rich_text/_index.md | 11 | 
7 files changed, 371 insertions, 0 deletions
| diff --git a/content/fate_v1/computations/_index.md b/content/fate_v1/computations/_index.md new file mode 100644 index 0000000..9312712 --- /dev/null +++ b/content/fate_v1/computations/_index.md @@ -0,0 +1,138 @@ +--- +title: Computations +--- +Computations are values. They may read from the memory, but do not modify it +(with a single exception). + +### TEXT +{{< fatecode >}}(text [C0 = COMPUTATION] ... [CN = COMPUTATION]){{< /fatecode >}} + +Returns a `text` node containing the text representation of `C0` ... `CN`. + +### VARIABLE | REFERENCE +{{< fatecode >}}(var {String}){{< /fatecode >}} + +Returns the value of the variable `{String}`, or a reference to it if +applicable. Structure members can be accessed by using `.` in `{String}`. + +### STRUCTURE FIELD ACCESS +{{< fatecode >}}{Structure Var Name}.{Field Name}{{< /fatecode >}} +{{< fatecode >}}(field [STRUCTURE VAR] {String}){{< /fatecode >}} + +Accesses the `{String}` field of the structure `<STRUCTURE_VAR>`. Using `.` to +access fields is recommended over the use of this operator. + +### STRUCTURE FIELD VALUE +{{< fatecode >}}(get_field [STRUCTURE] {String}){{< /fatecode >}} +Returns the value of the `{String}` field of the structure `[STRUCTURE]`. + +### TEMPORARY VARIABLES +{{< fatecode >}}(let (({V0 = String} [C0 = COMPUTATION]) ... ({VN = String} [CN = COMPUTATION])) [R = COMPUTATION]){{< /fatecode >}} + +Defines a hierarchical level and local variables `V0` ... `VN` with values `C0` ... `CN`, and returns the value of `[R]`. + +### CAST +{{< fatecode >}}(cast [TYPE] <COMPUTATION*>){{< /fatecode >}} + +Transforms `<COMPUTATION*>` into a value of type `[TYPE]`. Note that the variable +shorthand cannot be used for `<COMPUTATION*>`. The following type changes are +allowed: +* `[FLOAT]` to `[FLOAT]`, `[INT]`, and `[STRING]`. +* `[INT]` to `[FLOAT]`, `[INT]`, and `[STRING]`. +* `[BOOL]` to `[BOOL]` and `[STRING]`. +* `[STRING]` to `[BOOL]` (`true` and `false`), `[FLOAT]`, `[INT]`, and`[STRING]`. + +### RANDOM NUMBER +{{< fatecode >}}(rand [I0 = INT] [IN = INT]){{< /fatecode >}} + +Returns a random number between `I0` and `IN` (inclusive). + +## Basic Operators +### BOOL OPERATORS +{{< fatecode >}}(and [B0 = BOOL] ... [BN = BOOL]){{< /fatecode >}} + +Standard conjunction (minimum of 2 arguments). + +{{< fatecode >}}(or [B0 = BOOL] ... [BN = BOOL]){{< /fatecode >}} + +Standard disjunction (minimum of 2 arguments). + +{{< fatecode >}}(not [BOOL]){{< /fatecode >}} + +Standard negation. + +{{< fatecode >}}(implies [B0 = BOOL] [B1 = BOOL]){{< /fatecode >}} + +Standard implication. + + +{{< fatecode >}}(one_in [B0 = BOOL] ... [BN = BOOL]){{< /fatecode >}} + +true if, and only if, exactly one of the operands is true. + +### MATH OPERATORS +All operands must be of the same type, which is also the type returned by the +operation. + +{{< fatecode >}}(+ [N0 = NUMBER] ... [NN = NUMBER]){{< /fatecode >}} + +Standard addition (minimum of 2 arguments). + +{{< fatecode >}}(- [N0 = NUMBER] ... [NN = NUMBER]){{< /fatecode >}} + +Standard substraction (minimum of 2 arguments). + +{{< fatecode >}}(* [N0 = NUMBER] ... [NN = NUMBER]){{< /fatecode >}} + +Standard multiplication (minimum of 2 arguments). + +{{< fatecode >}}(/ [N0 = NUMBER] [N1 = NUMBER]){{< /fatecode >}} + +Standard division. Note that a division on integers is indeed a integer +division. + +{{< fatecode >}}(^ [N0 = NUMBER] [N1 = NUMBER]){{< /fatecode >}} + +Standard exponentiation. + +{{< fatecode >}}(% [I0 = INT] [I1 = INT]){{< /fatecode >}} + +Standard modulo operation. + +{{< fatecode >}}(min [N0 = NUMBER] ... [NN = NUMBER]){{< /fatecode >}} + +Lowest value among the operands. + +{{< fatecode >}}(max [N0 = NUMBER] ... [NN = NUMBER]){{< /fatecode >}} + +Highest value among the operands. + +{{< fatecode >}}(clamp [N0 = NUMBER] [N1 = NUMBER] [N2 = NUMBER]){{< /fatecode >}} + +Equivalent to `(min N0 (max N1 N2))`. + + +{{< fatecode >}}(abs [NUMBER]){{< /fatecode >}} + +Positive value of `[NUMBER]`. + +### COMPARISON OPERATORS +{{< fatecode >}}(= [C0 = COMPUTATION] ... [CN = COMPUTATION]){{< /fatecode >}} + +True if, and only if, all operands are equal. + +{{< fatecode >}}(< [C0 = COMPARABLE] [C1 = COMPARABLE]){{< /fatecode >}} + +True if, and only if, `C0` is strictly lower than `C1`. + +{{< fatecode >}}(=< [C0 = COMPARABLE] [C1 = COMPARABLE]){{< /fatecode >}} + +True if, and only if, `C0` is lower or equal to/than `C1`. + +{{< fatecode >}}(> [C0 = COMPARABLE] [C1 = COMPARABLE]){{< /fatecode >}} + +True if, and only if, `C0` is strictly higher than `C1`. + +{{< fatecode >}}(>= [C0 = COMPARABLE] [C1 = COMPARABLE]){{< /fatecode >}} + +True if, and only if, `C0` is higher or equal to/than `C1`. diff --git a/content/fate_v1/computations/collections/_index.md b/content/fate_v1/computations/collections/_index.md new file mode 100644 index 0000000..63c62cc --- /dev/null +++ b/content/fate_v1/computations/collections/_index.md @@ -0,0 +1,98 @@ +--- +title: Collections +--- +### ACCESS +{{< fatecode >}}(access [COLLECTION|COLLECTION PTR] [INT]){{< /fatecode >}} + +Returns the value of the `[INT]`th element in `[COLLECTION|COLLECTION PTR]`. + +### ACCESS CONSTANT INDEX +{{< fatecode >}}[(COLLECTION|COLLECTION PTR) VAR].{Integer}{{< /fatecode >}} + +Returns a variable corresponding to the `[INT]`th element in +`[(COLLECTION|COLLECTION PTR) VAR]`. + +### ACCESS POINTER +{{< fatecode >}}(access_pointer [(COLLECTION|COLLECTION PTR) VAR] [INT]){{< /fatecode >}} + +Returns a pointer to the `[INT]`th element in `[(COLLECTION|COLLECTION PTR) +VAR]`. + +### ADD ELEMENT AT +{{< fatecode >}}(add_element_at [INT] [COMPUTATION*] [LIST]){{< /fatecode >}} + +Returns a copy of `[LIST]` with `[COMPUTATION*]` added at index `[INT]`. Note +that `[COMPUTATION*]` does not allow use of the variable shorthand. + +### ADD ELEMENT +{{< fatecode >}}(add_element [COMPUTATION*] [COLLECTION]){{< /fatecode >}} + +Returns a copy of `[COLLECTION]` with `[COMPUTATION*]` added. If `[COLLECTION]` +is a `[LIST]`, then the element is added at the end of the list. +Note that `[COMPUTATION*]` does not allow use of the variable shorthand. + +### ADDING MEMBERS +{{< fatecode >}}(add_all_elements [C0 = COLLECTION] [C1 = COLLECTION]){{< /fatecode >}} + +Returns a copy of `[C1]`, with all the elements of `[C2]` added. If `[C1]` +is a `[LIST]`, the new members are added at the end of the list. + +### COUNT +{{< fatecode >}}(count [COMPUTATION*] [COLLECTION]){{< /fatecode >}} + +Returns the number of occurrences of `[COMPUTATION*]` in `[COLLECTION]`. +Note that `[COMPUTATION*]` does not allow use of the variable shorthand. + +### INDEX OF +{{< fatecode >}}(index_of [COMPUTATION] [COLLECTION]){{< /fatecode >}} + +Returns the index of the first occurrence of `[COMPUTATION]` in `[COLLECTION]`, +starting at 0. + +### IS MEMBER +{{< fatecode >}}(is_member [COMPUTATION] [COLLECTION]){{< /fatecode >}} + +Returns true if, and only if, `[COMPUTATION]` is in `[COLLECTION]`. + +### SIZE +{{< fatecode >}}(size [COLLECTION]){{< /fatecode >}} + +Returns the size (`[INT]`) of `[COLLECTION]`. + +### IS EMPTY +{{< fatecode >}}(is_empty [COLLECTION]){{< /fatecode >}} + +Returns true if, and only if `[COLLECTION]` is empty. + +### FILTER ELEMENTS +{{< fatecode >}}(filter [LAMBDA BOOL (X)] [X COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(filter [LAMBDA BOOL (X Y0 ... YN)] [X COLLECTION] [Y0 COMPUTATION*] ... [YN COMPUTATION*]){{< /fatecode >}} + +Returns a copy of `[X COLLECTION]` in which only the elements for which +`<LAMBDA BOOL (X)>` returns `true` remain. If the lambda function needs extra +parameters, use the second syntax, which adds those parameters at the end of the +`(filter ...)` call. Note that the variable shorthand cannot be used for these +extra parameters. + +### FILTER ELEMENTS (INDEXED) +{{< fatecode >}}(indexed_filter [LAMBDA BOOL (INT X)] [X COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(indexed_filter [LAMBDA BOOL (INT X Y0 ... YN)] [X COLLECTION] [Y0 COMPUTATION*] ... [YN COMPUTATION*]){{< /fatecode >}} + +Returns a copy of `[INT X COLLECTION]` in which only the elements for which +`<LAMBDA BOOL (INT X)>` (with `INT` being the element's index) returns `true` +remain. If the lambda function needs extra parameters, use the second syntax, +which adds those parameters at the end of the `(indexed_filter ...)` call. Note +that the variable shorthand cannot be used for these extra parameters. + +### FOLD OVER COLLECTION +{{< fatecode >}}(foldl [LAMBDA X (X Y)] [X COMPUTATION*] [Y COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(foldl [LAMBDA X (X Y Z0 ... ZN)] [X COMPUTATION*] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} +{{< fatecode >}}(foldr [LAMBDA X (X Y)> [X COMPUTATION*] [Y COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(foldr [LAMBDA X (X Y Z0 ... ZN)] [X COMPUTATION*] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} + +Returns the result of iterating `<LAMBDA X (X Y)>` over `[Y COLLECTION]`, with +`[X COMPUTATION*]` being the initial value. The direction of the iteration is +by ascending index order when using `foldl`, and the opposite order when using +`foldr`. Extra parameters for the lambda function can be passed as extra +parameters of the call. Note that the variable shorthand cannot be used for +those extra parameters, nor for the initial value. diff --git a/content/fate_v1/computations/conditionals/_index.md b/content/fate_v1/computations/conditionals/_index.md new file mode 100644 index 0000000..2953489 --- /dev/null +++ b/content/fate_v1/computations/conditionals/_index.md @@ -0,0 +1,54 @@ +--- +title: Conditionals +--- +This page presents the computation operators that allow a choice depending on +some condition. All possible returned values must be of the same type. + +### IF-ELSE +{{< fatecode >}}(if_else [BOOL] [C0 = COMPUTATION] [C1 = COMPUTATION]){{< /fatecode >}} + +Returns `C0` is `[BOOL]` yields true, `C1` otherwise. + +### COND +{{< fatecode >}}(cond ([B0 = BOOL] [C0 = COMPUTATION]) ... ([BN = BOOL] [CN = COMPUTATION])){{< /fatecode >}} + +Returns `<Ci>`, such that `<Bi>` is the first to hold true. If there is not such +`Bi`, returns `[CN]`. + +### SWITCH +{{< fatecode >}}(switch [T = COMPUTATION] ([V0 = COMPUTATION] [C0 = COMPUTATION]) ... ([VN = BOOL] [CN = COMPUTATION]) [D = COMPUTATION]){{< /fatecode >}}a + +Returns the first `Ci` such that `Vi` is equal to `T`. If there is not such +`Vi`, returns `[D]`. + +## Examples +{{< fatecode >}}(cond +   ((false) (false)) +   ((false) (false)) +   ((true) +      (cond +         ((false) (false)) +         ((true) (not (is_member 3 test_list))) +         ((true) (false)) +      ) +   ) +) +{{< /fatecode >}} + +{{< fatecode >}}(switch 3 +   (0 (false)) +   (1 (false)) +   (3 (true)) +   (2 (false)) +   (false) +) +{{< /fatecode >}} + +{{< fatecode >}}(if_else (true) +   (if_else (false) +      (assert (false) FAILED: instruction ifelse E) +      (set test_var (true)) +   ) +   (assert (false) FAILED: instruction ifelse F) +) +{{< /fatecode >}} diff --git a/content/fate_v1/computations/cons/_index.md b/content/fate_v1/computations/cons/_index.md new file mode 100644 index 0000000..5ece27b --- /dev/null +++ b/content/fate_v1/computations/cons/_index.md @@ -0,0 +1,22 @@ +--- +title: Cons +--- +Fate features a *construct* computation, making it possible to create an +anonymous structure by creating pairs of computations. Unlike collections, these +pairs do not have to be made of computations of the same type. + +### PAIRING +{{< fatecode >}}(cons [C0 = COMPUTATION*] [C1 = COMPUTATION*]){{< /fatecode >}} + +Returns the value corresponding to a pair made of `[C0]` and `[C1]`. Note that +the variable shorthand cannot be used for either parameter. + +### RETRIEVING THE FIRST ITEM +{{< fatecode >}}(car [CONS]){{< /fatecode >}} + +Returns the value corresponding to the first item in the `[CONS]` pair. + +### RETRIEVING THE SECOND ITEM +{{< fatecode >}}(cdr [CONS]){{< /fatecode >}} + +Returns the value corresponding to the second item in the `[CONS]` pair. diff --git a/content/fate_v1/computations/lambda_functions/_index.md b/content/fate_v1/computations/lambda_functions/_index.md new file mode 100644 index 0000000..35485a3 --- /dev/null +++ b/content/fate_v1/computations/lambda_functions/_index.md @@ -0,0 +1,30 @@ +--- +title: Lambda Functions +--- +Lambda functions are values that correspond to a computation not yet performed. +These can take arguments. Defining a lambda function returns the value that +corresponds to the function itself, the `eval` computation must be used to +obtain the value that the function computes. + +### DEFINITION +{{< fatecode >}}(lambda (([T0 = TYPE] {S0 = String}) ... ([TN = TYPE] {SN = String})) [COMPUTATION]){{< /fatecode >}} + +Returns a lambda function taking `S0` ... `SN` of types `T0` ... `TN` as +arguments and evaluating to `[COMPUTATION]`. + +### EVALUATION +{{< fatecode >}}(eval [REFERENCE] [C0 = COMPUTATION] ... [CN = COMPUTATION]){{< /fatecode >}} + +Returns the result of evaluating the lambda function at `[REFERENCE]` given the +parameters `C0` ... `CN`. + +## Examples +{{< fatecode >}}(lambda ( (int i) ) +   (+ (var i) 1) +) +{{< /fatecode >}} + +{{< fatecode >}}(lambda ( (int i) ) +   (* (eval int_to_int (var i)) 2) +) +{{< /fatecode >}} diff --git a/content/fate_v1/computations/references/_index.md b/content/fate_v1/computations/references/_index.md new file mode 100644 index 0000000..ba5716a --- /dev/null +++ b/content/fate_v1/computations/references/_index.md @@ -0,0 +1,18 @@ +--- +title: References +--- +### VALUE ACCESS +{{< fatecode >}}(at [ADDRESS]){{< /fatecode >}} + +Returns the variable at `[ADDRESS]`. + +### ALLOCATION +{{< fatecode >}}(new [TYPE]){{< /fatecode >}} + +Returns the address of a new variable of type `[TYPE]`. Don't forget to call +`free` on it once you're done. + +### ADDRESS +{{< fatecode >}}(ptr [COMPUTATION VARIABLE]){{< /fatecode >}} + +Returns the address of `[COMPUTATION VARIABLE]`. diff --git a/content/fate_v1/computations/rich_text/_index.md b/content/fate_v1/computations/rich_text/_index.md new file mode 100644 index 0000000..7351a5c --- /dev/null +++ b/content/fate_v1/computations/rich_text/_index.md @@ -0,0 +1,11 @@ +--- +title: Rich Text +--- +### RICH TEXT +{{< fatecode >}}(rich_text [TEXT]){{< /fatecode >}} + +### ADD TEXT EFFECT +{{< fatecode >}}(add_text_effect ({String} [P0 = COMPUTATION] ... [PN = COMPUTATION]) [RICH TEXT]){{< /fatecode >}} + +### NEW LINE +{{< fatecode >}}(newline){{< /fatecode >}} | 


