From e3174f1a67e626b6ebfe8889a466cc9630eea3a5 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 21 Dec 2020 15:07:21 -0500 Subject: Add Floor and comparison function specifications --- docs/spec/primitive.html | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'docs/spec') diff --git a/docs/spec/primitive.html b/docs/spec/primitive.html index 36a22cfb..f2bd43bb 100644 --- a/docs/spec/primitive.html +++ b/docs/spec/primitive.html @@ -6,15 +6,16 @@

Specification: BQN primitives

Most primitives are specified by the BQN-based implementation in reference.bqn. This document specifies the basic functionality required by those definitions. Descriptions of other primitives are for informational purposes only.

-

Arithmetic

-

Functions here are defined for atoms only; the reference implementations extend them to arrays.

+

Pervasive primitives

+

Functions in this section are defined for atoms only; the reference implementations extend them to arrays.

+

Arithmetic

BQN uses five arithmetic functions that are standard in mathematics. The precision of these operations should be specified by the number type.

The three higher functions ร—, รท, and โ‹† apply to numbers and no other atomic types. + and - apply to numbers, and possibly also to characters, according to the rules of the affine character type:

In the first two cases, if the result would not be a valid Unicode code point, then an error results. The remaining cases of + and - (adding two characters; negating a character or subtracting it from a number) are not allowed.

+

Additionally, the Floor function โŒŠ returns the largest integer smaller than the argument, or the argument itself if it is ยฏโˆž or โˆž. It's needed because the arithmetic operations give no fixed-time way to determine if a value is an integer. Floor gives an error if the argument is an atom other than a number.

+

Comparison

+

Two kinds of comparison are needed to define BQN's primitives: equality comparison and ordered comparison.

+

Ordered comparison is simpler and is provided by the dyadic Less than or Equal to (โ‰ค) function. This function gives an error if either argument is an operation, so it needs to be defined only for numbers and characters. For numbers it is defined by the number system, and for characters it returns 1 if the left argument's code point is less than that of the right argument. Characters are considered greater than numbers, so that nโ‰คc is 1 and cโ‰คn is 0 if c is a character and n is a number.

+

The dyadic function =, representing equality comparison, can be applied to any two atoms without an error. Roughly speaking, it returns 1 if they are indistinguishable within the language and 0 otherwise. If the two arguments have different types, the result is 0; if they have the same type, the comparison depends on type:

+ +

Operations are split into subtypes depending on how they were created.

+ +

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.

-- cgit v1.2.3