From b0f8a1d80d0a10160359fc6445a4f398ca71f7d2 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 13 May 2021 20:46:20 -0400 Subject: Add namespaces to types page and correct discussion on mutability --- doc/types.md | 31 ++++++++++++++++++------------- docs/doc/types.html | 38 ++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/doc/types.md b/doc/types.md index a78dbdb4..3e37ffed 100644 --- a/doc/types.md +++ b/doc/types.md @@ -10,31 +10,32 @@ BQN supports the following fundamental types: - [Function](#functions) - 1-[Modifier](#modifiers) - 2-[Modifier](#modifiers) +- [Namespace](#namespaces) -The first three types are called *data types*, and the rest are *operation types*. The array is the only *compound type*; the other types are *atomic types* and values of these types are called *atoms*. The fact that an array is only one type of many is common in modern programming languages but a novelty in the APL family. This decision is discussed in the page on [based array theory](based.md). +The first three types, called *data types*, are immutable; the others are mutable. Functions and modifiers together are the *operation types*. Types other than the array are *atomic types* and values of these types are called *atoms*. The fact that an array is only one type of many is common in modern programming languages but a novelty in the APL family. This decision is discussed in the page on [based array theory](based.md). -All of these types are immutable, meaning that a particular copy of a value will never change (to go further, with immutable types it doesn't really make sense to talk about a "copy" of a value: values just exist and nothing you do will affect them). The only form of mutability BQN has is the ability to change the value of a particular variable, that is, make the variable refer to a different value. Such a change can also change the behavior of a function or modifier that has the variable in its scope, and in this sense operation types are mutable—in fact it is possible to implement typical mutable data structures as functions that act on enclosed state. +The reason operations and namespaces are called "mutable" is that the values obtained from them—by calling an operation on particular arguments or reading a field from a namespace—may change over the course of the program. This property is caused by variable modification `↩`, which can directly change a namespace field, or change the behavior of an operation that uses the modified variable. This means that a program that doesn't include `↩` won't have such changes in behavior. However, there will still be an observable difference between immutable data and the mutable types: code that creates a mutable value (for example, a block function `{𝕩}`) creates a different one each time, so that two different instances don't match (`≡`) each other. Data values created at different times may match, but mutable values never will. -It is likely that in the future [namespaces](extensions.md#namespaces-and-symbols), or references to enclosed scopes, will be added as a more directly manipulable mutable data type. +An array is considered immutable because its shape, and what elements it contains, cannot change. An array has no identity outside these properties (and possibly its fill element), so an array with a different shape or different elements would simply be a different array. However, any element of an array could be mutable, in which case the behavior of the array would change with respect to the operation of selecting that element and calling it or accessing a field. ## Data types @@ -87,3 +88,7 @@ A function is called with one or two arguments. A data value (number, character, ### Modifiers A 1-modifier is called with one operand, while a 2-modifier is called with two. In contrast to functions, these are distinct types, and it is impossible to have a value that can be called with either one or two operands. Also in contrast to functions, data values cannot be called as modifiers: they will cause an error if called this way. + +## Namespaces + +Functions and modifiers have internal scopes which they can manipulate (by defining and modifying variables) to save and update information. Namespaces let the programmer to expose this state more directly: identifiers in a namespace may be exported, allowing code outside the namespace to read their values. They are described in detail [here](namespace.md). diff --git a/docs/doc/types.html b/docs/doc/types.html index c1786660..f228bd0f 100644 --- a/docs/doc/types.html +++ b/docs/doc/types.html @@ -13,33 +13,37 @@
  • Function
  • 1-Modifier
  • 2-Modifier
  • +
  • Namespace
  • -

    The first three types are called data types, and the rest are operation types. The array is the only compound type; the other types are atomic types and values of these types are called atoms. The fact that an array is only one type of many is common in modern programming languages but a novelty in the APL family. This decision is discussed in the page on based array theory.

    - +

    The first three types, called data types, are immutable; the others are mutable. Functions and modifiers together are the operation types. Types other than the array are atomic types and values of these types are called atoms. The fact that an array is only one type of many is common in modern programming languages but a novelty in the APL family. This decision is discussed in the page on based array theory.

    + - - - + + + + - Number - Function - Character - 1-modifier - Array - 2-modifier + Number + Character + Array + Function + 1-modifier + 2-modifier + Namespace - Data - Operation - Atom + Data + Mutable + Operation + Atom -

    All of these types are immutable, meaning that a particular copy of a value will never change (to go further, with immutable types it doesn't really make sense to talk about a "copy" of a value: values just exist and nothing you do will affect them). The only form of mutability BQN has is the ability to change the value of a particular variable, that is, make the variable refer to a different value. Such a change can also change the behavior of a function or modifier that has the variable in its scope, and in this sense operation types are mutable—in fact it is possible to implement typical mutable data structures as functions that act on enclosed state.

    -

    It is likely that in the future namespaces, or references to enclosed scopes, will be added as a more directly manipulable mutable data type.

    +

    The reason operations and namespaces are called "mutable" is that the values obtained from them—by calling an operation on particular arguments or reading a field from a namespace—may change over the course of the program. This property is caused by variable modification , which can directly change a namespace field, or change the behavior of an operation that uses the modified variable. This means that a program that doesn't include won't have such changes in behavior. However, there will still be an observable difference between immutable data and the mutable types: code that creates a mutable value (for example, a block function {𝕩}) creates a different one each time, so that two different instances don't match () each other. Data values created at different times may match, but mutable values never will.

    +

    An array is considered immutable because its shape, and what elements it contains, cannot change. An array has no identity outside these properties (and possibly its fill element), so an array with a different shape or different elements would simply be a different array. However, any element of an array could be mutable, in which case the behavior of the array would change with respect to the operation of selecting that element and calling it or accessing a field.

    Data types

    Data types—numbers, characters, and arrays—are more like "things" than "actions". If called as a function, a value of one of these types simply returns itself. Data can be uniquely represented, compared for equality, and ordered using BQN's array ordering; in contrast, determining whether two functions always return the same result can be undecidable. For arrays, these properties apply only if there are no operations inside. We might say that "data" in BQN refers to numbers, characters, and arrays of data.

    Numbers

    @@ -64,3 +68,5 @@

    A function is called with one or two arguments. A data value (number, character, or array) can also be called the same way, but only a function takes any action when passed arguments, as data just returns itself. Both the one-argument and two-argument calls are considered function calls, and it's common for a function to allow both. A function that always errors in one case or the other might be called a one-argument or two-argument function, depending on which case is allowed.

    Modifiers

    A 1-modifier is called with one operand, while a 2-modifier is called with two. In contrast to functions, these are distinct types, and it is impossible to have a value that can be called with either one or two operands. Also in contrast to functions, data values cannot be called as modifiers: they will cause an error if called this way.

    +

    Namespaces

    +

    Functions and modifiers have internal scopes which they can manipulate (by defining and modifying variables) to save and update information. Namespaces let the programmer to expose this state more directly: identifiers in a namespace may be exported, allowing code outside the namespace to read their values. They are described in detail here.

    -- cgit v1.2.3