From e8d6aa976783bcb7cb5855880ff056a023f12471 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 12 Jun 2021 22:26:00 -0400 Subject: Update some documentation to account for namespaces --- doc/embed.md | 2 +- doc/glossary.md | 3 ++- doc/match.md | 6 +++--- docs/doc/embed.html | 2 +- docs/doc/glossary.html | 3 ++- docs/doc/match.html | 6 +++--- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/embed.md b/doc/embed.md index 1455d3cb..32f14536 100644 --- a/doc/embed.md +++ b/doc/embed.md @@ -42,7 +42,7 @@ You can also use an array to pass multiple functions or other values from JS int ## JS encodings -In the programs above we've used numbers and functions of one argument, which mean the same thing in BQN and JS. This isn't the case for all types: although every BQN value is stored as some JS value, the way it's represented may not be obvious and there are many JS values that don't represent any BQN value and could cause errors. BQN operations don't verify that their inputs are valid BQN values (this would have a large performance cost), so it's up to the JS programmer to make sure that values passed in are valid. To do this, you need to know the encodings for each of the six BQN [types](types.md). +In the programs above we've used numbers and functions of one argument, which mean the same thing in BQN and JS. This isn't the case for all types: although every BQN value is stored as some JS value, the way it's represented may not be obvious and there are many JS values that don't represent any BQN value and could cause errors. BQN operations don't verify that their inputs are valid BQN values (this would have a large performance cost), so it's up to the JS programmer to make sure that values passed in are valid. To do this, you need to know the encodings for each of the seven BQN [types](types.md) you're going to use. The two atomic data values are simple: numbers are just JS numbers, and characters are strings containing a single code point. Arrays *are* JS arrays, but with some extra information. Since JS arrays are 1-dimensional, a BQN array `a` is stored as the element list `⥊a`. Its shape `≢a`, a list of numbers, is `a.sh` in JS (the shape isn't necessarily a BQN array so it doesn't have to have a `sh` property). Optionally, its fill element is `a.fill`. Note that a BQN string is not a JS string, but instead an array of BQN characters, or JS strings. To convert it to a JS string you can use `str.join("")`. diff --git a/doc/glossary.md b/doc/glossary.md index eba5e8c3..d16f5584 100644 --- a/doc/glossary.md +++ b/doc/glossary.md @@ -7,7 +7,7 @@ Below are short, and sometimes vague, definitions of terms used to describe BQN ## Types * **Value**: Something that can be stored in variables and manipulated by a BQN programmer. -* [**Type**](types.md): One of six possible kinds of value. +* [**Type**](types.md): One of seven possible kinds of value. The possible types are: * [**Number**](types.md#numbers): Like some caveman was counting but then forty thousand years of math happened to it. @@ -16,6 +16,7 @@ The possible types are: * [**Function**](types.md#functions): An operation that is called on one or two arguments. * [**1-modifier**](types.md#modifiers): An operation that is called on one operand. * [**2-modifier**](types.md#modifiers): An operation that is called on two operands. +* [**Namespace**](namespace.md): A container for variables, some of which are exposed as fields. A few terms refer to multiple types collectively: * **Atom**: A value that's not an array. diff --git a/doc/match.md b/doc/match.md index 72bd3546..96b5c4c9 100644 --- a/doc/match.md +++ b/doc/match.md @@ -21,7 +21,7 @@ To give a precise definition, two arrays are considered to match if they have th ## Atomic equality -Atoms in BQN have five possible [types](types.md): number, character, function, 1-modifier, and 2-modifier. Equality is not allowed to fail for any two arguments, so it needs to be defined on all of these types. +Atoms in BQN have six possible [types](types.md): number, character, function, 1-modifier, 2-modifier, and namespace. Equality is not allowed to fail for any two arguments, so it needs to be defined on all of these types. Starting with the easiest rules, values with different types are never equal to each other. @@ -32,10 +32,10 @@ Two characters are equal when they have the same code point. Numeric equality de 'x' = "wxyz" 1.25 = 1 + 0.25 -Operations are more difficult. Here there are three cases: +Mutable types are more difficult. Here there are three cases: - Primitives are equal if they have the same glyph. - Compound functions or modifiers are split into components. -- Block instances are equal if they are the same instance. +- Block instances or namespaces are equal if they are the same instance. The first two are fairly similar to how numbers and arrays work. Primitives and compounds like trains, or modifiers with bound operands, are immutable, so they are defined purely by what components they contain. diff --git a/docs/doc/embed.html b/docs/doc/embed.html index bd3bb94c..de7709ca 100644 --- a/docs/doc/embed.html +++ b/docs/doc/embed.html @@ -33,7 +33,7 @@

When defining closures for their side effects like this, make sure they are actually functions! For example, since flip ignores its argument (you can call it with flip(), because a right argument of undefined isn't valid but will just be ignored), it needs an extra 𝕤 in the definition to be a function instead of an immediate block.

You can also use an array to pass multiple functions or other values from JS into BQN all at once. However, a JS array can't be used directly in BQN because its shape isn't known. The function list() converts a JS array into a BQN list by using its length for the shape; the next section has a few more details.

JS encodings

-

In the programs above we've used numbers and functions of one argument, which mean the same thing in BQN and JS. This isn't the case for all types: although every BQN value is stored as some JS value, the way it's represented may not be obvious and there are many JS values that don't represent any BQN value and could cause errors. BQN operations don't verify that their inputs are valid BQN values (this would have a large performance cost), so it's up to the JS programmer to make sure that values passed in are valid. To do this, you need to know the encodings for each of the six BQN types.

+

In the programs above we've used numbers and functions of one argument, which mean the same thing in BQN and JS. This isn't the case for all types: although every BQN value is stored as some JS value, the way it's represented may not be obvious and there are many JS values that don't represent any BQN value and could cause errors. BQN operations don't verify that their inputs are valid BQN values (this would have a large performance cost), so it's up to the JS programmer to make sure that values passed in are valid. To do this, you need to know the encodings for each of the seven BQN types you're going to use.

The two atomic data values are simple: numbers are just JS numbers, and characters are strings containing a single code point. Arrays are JS arrays, but with some extra information. Since JS arrays are 1-dimensional, a BQN array a is stored as the element list a. Its shape a, a list of numbers, is a.sh in JS (the shape isn't necessarily a BQN array so it doesn't have to have a sh property). Optionally, its fill element is a.fill. Note that a BQN string is not a JS string, but instead an array of BQN characters, or JS strings. To convert it to a JS string you can use str.join("").

There are two utilities for converting from JS to BQN data: list([…]) converts a JS array to a BQN list, and str("JS string") converts a string.

Operations are all stored as JS functions, with one or two arguments for the inputs. The type is determined by the .m property, which is 1 for a 1-modifier and 2 for a 2-modifier, and undefined or falsy for a function. Functions might be called with one or two arguments. In either case, 𝕩 is the first argument; 𝕨, if present, is the second. Note that F(x,w) in JS corresponds to w F x in BQN, reversing the visual ordering of the arguments! For modifiers there's no such reversal, as 𝕗 is always the first argument, and for 2-modifiers 𝕘 is the second argument. As in BQN, a modifier may or may not return a function.

diff --git a/docs/doc/glossary.html b/docs/doc/glossary.html index 526d028c..02f6d1da 100644 --- a/docs/doc/glossary.html +++ b/docs/doc/glossary.html @@ -9,7 +9,7 @@

Types

The possible types are:

A few terms refer to multiple types collectively: