From 4098cbf57bf596bbad2d107f923caba8b701277a Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 21 Dec 2020 17:15:57 -0500 Subject: Specify the remaining provided functions for reference.bqn --- spec/primitive.md | 30 ++++++++++++++++++++++++++++++ spec/reference.bqn | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/primitive.md b/spec/primitive.md index 859bfe27..21306fef 100644 --- a/spec/primitive.md +++ b/spec/primitive.md @@ -44,3 +44,33 @@ Operations are split into subtypes depending on how they were created. - Block instances are equal if they are the same instance. This means that block instance equality indicates identity in the context of mutability: two block instances are equal if any change of state in one would be reflected in the other as well. The concept of identity holds even if the blocks in question have no way of changing or accessing state. For example, `=β—‹{𝕩⋄{𝕩}}˜@` is `0` while `=Λœβ—‹{𝕩⋄{𝕩}}@` is `1`. + +## Array functionality + +Several subsets of primitives, or dedicated operations, are used to manipulate arrays in the reference implementation. + +- `IsArray` returns `1` if the argument is an array and `0` if it's an atom. + +The following functions translate between arrays and the two lists that define them: the shape and ravel. + +- **Shape** (`β‰’`) returns the shape of array `𝕩`, as a list of natural numbers. +- **Deshape** (monadic `β₯Š`) returns the ravel of array `𝕩`, that is, the list of its elements. +- **Reshape** (dyadic `β₯Š`) returns an array with the same ravel as `𝕩` with shape `𝕨`. It can be assumed that `≒𝕩` and `𝕨` have the same product. + +The following functions manipulate lists. In these functions, a valid index for list `l` is a natural number less than the length of `l`. + +- **Range** gives the list of length `𝕩` (a natural number) with value `i` at any index `i`. +- **Pick** (`βŠ‘`) selects the element at index `𝕨` from list `𝕩`. +- `_amend` returns an array identical to list `𝕩` except that the element at index `𝕗` is changed to `𝕨`. + +## Inferred functionality + +Inferred properties are specified in [their own document](inferred.md), not in the reference implementation. + +- `Identity` gives the identity value for reduction by function `𝕏`. +- **Undo** (`⁼`) gives a partial right inverse for function `𝔽`. +- `Type` gives the enclose of the fill value for array `𝕩`. + +## 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). diff --git a/spec/reference.bqn b/spec/reference.bqn index a3b9046b..6e88da0a 100644 --- a/spec/reference.bqn +++ b/spec/reference.bqn @@ -30,8 +30,8 @@ IsArray # Return 1 if 𝕩 is an array ! # 𝕩 is 0 or 1; throw an error if it's 0 β‰’ # LIMITED to monadic case β₯Š # LIMITED to array 𝕩 and (×´𝕨)≑≒𝕩 -βŠ‘ # LIMITED to natural number 𝕩 and vector 𝕨 -_amend # {(π•—βŠ‘π•©)↩𝕨⋄𝕩} +βŠ‘ # LIMITED to natural number 𝕨 and list 𝕩 +_amend # {π•¨Λ™βŒΎ(π•—βŠΈβŠ‘)𝕩} ↕ # LIMITED to number 𝕩 Identity # Left or right identity of function 𝕏 ⁼ # Inverse of function 𝔽 -- cgit v1.2.3