diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-12-22 21:49:26 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-12-22 21:51:48 -0500 |
| commit | 6267150a30c482dd5539689a4afc508f7855ef24 (patch) | |
| tree | 5fe6c354dd04eaa2aef90175db6510432032fc38 /spec | |
| parent | 7b0ce52421b2f657f6e1bfdbff8cbf7ef48856bf (diff) | |
Spec commentary sections on combinators and array properties
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/primitive.md | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/primitive.md b/spec/primitive.md index 028cd80d..f888c0b9 100644 --- a/spec/primitive.md +++ b/spec/primitive.md @@ -74,3 +74,33 @@ Inferred properties are specified in [their own document](inferred.md), not in t ## Other provided functionality - **Assert** (`!`) causes an error if the argument is not `1`. If `π¨` is provided, it gives a message to be associated with this error (which can be any value, not necessarily a string). + +## Commentary on other primitives + +As noted above, see [reference.bqn](reference.bqn) for the authoritative definitions. Commentary here gives an overall description and highlights implementation subtleties and edge cases. + +### Combinators + +There's little to say about BQN's true combinators, since each is simply a pattern of function application. All primitive combinators use their operands as functions, and thus treat a data operand as a constant function. + +- **Choose** (`βΆ`) is later redefined to use the complete `β` rather than the simple version assumed (using this primitive means it's not a true combinator). +- **Constant** (`Λ`) +- **Valences** (`β`) uses a trick with ambivalent `-` to find out whether there's a left argument, described below. +- **Right** (`β’`) +- **Left** (`β£`) +- **Self**/**Swap** (`Λ`) +- **Atop** (`β`) +- **Over** (`β`) +- **Before**/**Bind** (`βΈ`) +- **After**/**Bind** (`β`) + +The somewhat complicated definition of Valences could be replaced with `{π½π©;π¨πΎπ©}` using headers. However, reference.bqn uses a simple subset of BQN's syntax that doesn't include headers. Instead, the definition relies on the fact that `π¨` works like `Β·` if no left argument is given: `(1Λπ¨)-0` is `1-0` or `1` if `π¨` is present and `(1ΛΒ·)-0` otherwise: this reduces to `Β·-0` or `0`. + +### Array properties + +The reference implementations extend Shape (`β’`) to atoms as well as arrays, in addition to implementing other properties. In all cases, an atom behaves as if it has shape `β¨β©`. The functions in this section never cause an error. + +- **Shape** (`β’`) gives the shape of an array or atom. +- **Rank** (`=`) gives the length of the shape. +- **Length** (`β `) gives the number of major cells, or `1` for an argument of rank `0`. +- **Depth** (`β‘`) gives the nesting depth. It ignores the shapes of arrays, and considering only the depths of their elements. |
