From adc8dfaace36ecf40b80f5ef460c5084f82f7d22 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 26 Jun 2020 20:32:46 -0400 Subject: =?UTF-8?q?Allow=20nothing=20(=C2=B7)=20as=20left=20tine=20of=20a?= =?UTF-8?q?=20fork?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/evaluate.md | 12 ++++++------ spec/grammar.md | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/evaluate.md b/spec/evaluate.md index ba6830d5..03edc813 100644 --- a/spec/evaluate.md +++ b/spec/evaluate.md @@ -22,11 +22,11 @@ Rules in the table below are function and operator evaluation. In each case the constituent expressions are evaluated in reverse source order: Right, then Called, then Left. Then the expression's result is obtained by calling the Called value on its parameters. A left argument of `nothing` is not used as a parameter, leaving only a right argument in that case. The data type of the Called value must be appropriate to the expression type, as indicated in the "Types" column. For function application, a value type (number, character, or array) is allowed. It is called simply by returning itself. Although the arguments are ignored in this case, they are still evaluated. A braced construct is evaluated by binding the parameter names given in columns L and R to the corresponding values. Then if all parameter levels present have been bound, its body is evaluated to give the result of application. The following rules derive new functions or operators from existing ones. -| Left | Center | Right | Result -|-----------|-----------|---------------------|-------------- -| | `_comp_` | `( value \| Func )` | `{š”½ _C_ R}` -| `Operand` | `_comp_` | | `{L _C_ š”½}` -| `Operand` | `Func` | `Fork` | `{(š•ØLš•©)C(š•ØRš•©)}` -| | `Func` | `Fork` | `{ C(š•ØRš•©)}` +| Left | Center | Right | Result +|------------|-----------|---------------------|-------------- +| | `_comp_` | `( value \| Func )` | `{š”½ _C_ R}` +| `Operand` | `_comp_` | | `{L _C_ š”½}` +| `Operand` | `Func` | `Fork` | `{(š•ØLš•©)C(š•ØRš•©)}` +| `nothing?` | `Func` | `Fork` | `{ C(š•ØRš•©)}` As with applications, all expressions are evaluated in reverse source order before doing anything else. Then a result is formed without calling the center value. Its value in BQN is given in the rightmost column, using `L`, `C`, and `R` for the results of the expressions in the left, center, and right columns, respectively. For the first two rules (*partial application*), the given operand is bound to the composition: the result is a modifier that, when called, calls the center composition with the bound operand on the same side it appeared on and the new operand on the remaining side. A *train* is a function that, when called, calls the right-hand function on all arguments, then the left-hand function, and calls the center function with these results as arguments. In a composition partial application, the result will fail when applied if the center value does not have the composition type, and in a fork, it will fail if any component has a modifier or composition type (that is, cannot be applied as a function). BQN implementations are not required to check for these types when forming the result of these expressions, but may give an error on formation even if the result will never be applied. diff --git a/spec/grammar.md b/spec/grammar.md index 8a20deee..a2cddf87 100644 --- a/spec/grammar.md +++ b/spec/grammar.md @@ -38,6 +38,7 @@ Functions can be formed by fully applying operators or as trains. Operators are | Derv Fork = Func | Operand Func Fork ā 3-train + | nothing Func Fork ā 2-train Train = Fork | Func Fork ā 2-train FuncExpr = Train -- cgit v1.2.3