From 0135f65e0baec4d7913c9619b0fae6d1eb867a17 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 19 Aug 2020 22:11:05 -0400 Subject: Move syntax overview to its own page --- docs/index.html | 97 --------------------------------------------------------- 1 file changed, 97 deletions(-) (limited to 'docs/index.html') diff --git a/docs/index.html b/docs/index.html index 8671db3e..54c04f47 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,89 +33,6 @@

Array model

Most of BQN's functionality deals with the manipulation of multidimensional arrays. However, it discards many of the complications of traditional APL array models. Unlike in APL, non-array data is possible, and common: numbers, characters, and functions are not arrays (see the full list of types below). This avoids some difficulties that show up when trying to treat scalar arrays as the fundamental unit; in particular, there is no "floating" so a value is always different from a scalar array that contains it. This system has been proposed in APL's past under the name based array theory.

Currently, the intention is that arrays will not have prototypes, so that all empty arrays of the same shape behave identically. Different elements of an array should not influence each other. While some APLs force numbers placed in the same array to a common representation, which may have different precision properties, BQN will enforce 64-bit floating-point precision, and only use representations or methods compatible with it (for example, integers up to 32 bits).

-

Syntax

-

BQN syntax consists of expressions where computation is done with a little organizing structure around them like assignment, functions, and list notation. Expressions are where the programmer is in control so the design tries to do as much as possible with them before introducing special syntax.

-

Expressions

-

Like APL, BQN uses four syntactic roles for values in expressions:

- -

These roles work exactly like they do in APL, with functions applying to one or two subject arguments, 1-modifiers taking a single function or subject on the left, and 2-modifiers taking a function or subject on each side.

-

Unlike APL, in BQN the syntactic role of a value is determined purely by the way it's spelled: a lowercase first letter (name) makes it a subject, an uppercase first letter (Name) makes it a function, and underscores are used for 1-modifiers (_name) and 2-modifiers (_name_). Below, the function {π•Žπ•©} treats its left argument π•Ž as a function and its right argument 𝕩 as a subject. With a list of functions, we can make a table of the square and square root of a few numbers:

-
    βŸ¨Γ—Λœ,√⟩ {π•Žπ•©}⌜ 1β€Ώ4β€Ώ9
-β”Œβ”€         
-β•΅ 1 16 81  
-  1  2  3  
-          β”˜
-
-

BQN's built-in operations also have patterns to indicate the syntactic role: 1-modifiers (˜¨˘⁼⌜´`) are all superscript characters, and 2-modifiers (βˆ˜β—‹βŠΈβŸœβŒΎβŠ˜β—Άβš‡βŽ‰βŸ) all have an unbroken circle (two functions βŒ½β‰ have broken circles with lines through them). Every other built-in constant is a function, although the special symbols Β―, ∞, and Ο€ are used as part of numeric literal notation.

-

Special syntax

-

Most of these glyphs are explained further in the section on literal notation.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Glyph(s)Meaning
←Define
↩Change
β†’Return
β‹„, or newlineStatement or element separator
()Expression grouping
{}Explicit function or modifier
⟨⟩List (rank-1 array)
β€ΏStrand (lightweight list syntax)
π•¨π•ŽLeft argument
𝕩𝕏Right argument
𝕗𝔽Left operand of a modifier
π•˜π”ΎRight operand of a 2-modifier
#Comment

Built-in operations

Functions

Functions that have significant differences from APL functions are marked with an asterisk. Links for these entries go to dedicated BQN documentation while other links go to the APL Wiki.

@@ -448,20 +365,6 @@ -

Literal notation

-

Constant notation

-

BQN has single-token notation for numbers, strings, and characters.

-

Numbers allow the typical decimal notation with Β― for the negative sign (because - is a function) and e for scientific notation (or E, as numeric notation is case-insensitive). ∞ and Ο€ may be used as special numeric values. Complex numbers are also allowed, with the components separated by i.

-

Strings are written with double quotes "", and characters with single quotes '' with a single character in between. A double quote within a string can be escaped by writing it twice; if two string literals are next to each other, they must be separated by a space. In contrast, character literals do not use escapes, as the length is already known.

-

Separators

-

The characters β‹„ and , and newline are completely interchangeable and are used to separate expressions. An expression might be an element in a list or a line in a function. Empty sectionsβ€”those that consist only of whitespaceβ€”are ignored. This means that any number of separators can be used between expressions, and that leading and trailing separators are also allowed. The expressions are evaluated in text order: left to right and top to bottom.

-

List notation

-

Lists (1-dimensional arrays) are enclosed in angle brackets ⟨⟩, with the results of the expressions in between being the list's elements. Lists of two elements or more can also be written with the ligature character β€Ώ. This character has higher binding strength than any part of an expression. If one of the elements is a compound expression, then it will need to be enclosed in parentheses.

-

If added, sets and dictionaries would also use a list-like notation.

-

Blocks

-

Blocks are written with curly braces {} and can be used to group expressions or define functions and modifiers. The contents are simply a sequence of expressions, where each is evaluated and the result of the last is returned in order to evaluate the block. This result can have any value, and its syntactic role in the calling context is determined by the normal rules: functions return subjects and modifiers return functions. Blocks have lexical scope.

-

The special names 𝕨 and 𝕩, which stand for arguments, and 𝕗 and π•˜, which stand for operands, are available inside curly braces. Like ordinary names, the lowercase forms indicate subjects and the uppercase forms π•Žπ•π”½π”Ύ indicate functions. The type and syntactic role of the block is determined by its contents: a 2-modifier contains π•˜, a 1-modifier contains 𝕗 but not π•˜, and a function contains neither but does have one of π•¨π•©π•€π•Žπ•π•Š. If no special names are present the block is an immediate block and is evaluated as soon as it appears, with the result having a subject role.

-

A modifier can be evaluated twice: once when passed operands and again when the resulting function is passed arguments. If it contains 𝕨 or 𝕩, the first evaluation simply remembers the operands, and the contents will be executed only on the second evaluation, when the arguments are available. If it doesn't contain these, then the contents are executed on the first evaluation and the result is treated as a function.

Types

BQN will initially support the following fundamental types: