From 4ac3f5940a89dcbc165479603689e02c29f50feb Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 23 Jun 2022 16:33:26 -0400 Subject: Document [] notation --- docs/doc/expression.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'docs/doc/expression.html') diff --git a/docs/doc/expression.html b/docs/doc/expression.html index b2f40951..067eed73 100644 --- a/docs/doc/expression.html +++ b/docs/doc/expression.html @@ -5,7 +5,7 @@

Expression syntax

-

BQN expressions are the part of syntax that describes computations to perform. Programs are mainly made up of expressions with a little organizing material like blocks and namespaces around them. This page explains how functions, modifiers, and assignment combine with their inputs. It doesn't describe constant and array literals, which each form a single subject for grammatical purposes.

+

BQN expressions are the part of syntax that describes computations to perform. Programs are mainly made up of expressions with a little organizing material like blocks and namespaces around them. This page explains how functions, modifiers, and assignment combine with their inputs. It doesn't describe constant and array literals, which each form a single subject for grammatical purposes.

The first tutorial also covers how to build and read BQN expressions.

Overview

BQN expressions consist of subjects, functions, and modifiers arranged in sequence, with parentheses to group parts into subexpressions. Assignment arrows and can also be present and mostly behave similar to functions. Functions can be applied to subjects or grouped into trains, while modifiers can be applied to subjects or functions. The most important kinds of application are:

@@ -106,7 +106,7 @@

Primitive tokens, since they have a fixed value, always have a role that matches their type. They are functions, unless they fall into one of the two modifier patterns. 1-modifiers have superscript glyphs, and 2-modifiers have glyphs with an unbroken circle—that is, one without a line through it, excluding functions and .

Variable names can be written in any case and with underscores added, and these changes don't affect what identifier the name refers to. ab, aB, AB, and _a_B_ are all the same variable. However, the spelling—specifically the first and last characters—determine the variable's role. A lowercase first letter indicates a subject, and an uppercase first letter makes it a function. A leading underscore (regardless of the following character) indicates a 1-modifier, and both leading and trailing underscores makes a 2-modifier.

-

Besides these, character, string, and list literals always have a subject role, and the role of a block is determined by its type, which depends either on the header it has or which special variables it uses.

+

Besides these, character, string, and array literals always have a subject role, and the role of a block is determined by its type, which depends either on the header it has or which special variables it uses.

The role of a compound expression, formed by applying an operation to some inputs, depends on the operation applied. This system is discussed in the remaining sections below.

Nothing

The character · is called Nothing. While it can be easier to think of it as a value, it can't be passed around in variables, and so can also be interpreted as an element of syntax. The special name 𝕨 also functions as Nothing if the block that contains it is called with one argument (the uppercase spelling 𝕎 doesn't, but instead immediately causes an error). Both · and 𝕨 have a subject role.

@@ -218,6 +218,16 @@ s ⟨ 0 1 2 3 ⟩ +

Array destructuring using [] is also possible: it's equivalent to splitting the right-hand side with <˘ and then applying list destructuring.

+↗️
    [t,u]  23
+┌─                         
+╵ ⟨ 0 0 ⟩ ⟨ 0 1 ⟩ ⟨ 0 2 ⟩  
+  ⟨ 1 0 ⟩ ⟨ 1 1 ⟩ ⟨ 1 2 ⟩  
+                          ┘
+
+    u
+⟨ ⟨ 1 0 ⟩ ⟨ 1 1 ⟩ ⟨ 1 2 ⟩ ⟩
+

Namespace destructuring uses an overlapping syntax, fully described in its own section. The left hand side is a list of names or aliases tofrom.

↗️
    qr  {q2+r0.5}  q
 2.5
-- 
cgit v1.2.3