From 8b115bd20d7a91361a7fe87f293a8a53ff12406c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 5 Jun 2022 17:19:14 -0400 Subject: Editing continues --- docs/doc/oop.html | 20 ++++++++++---------- docs/doc/order.html | 24 +++++++++++------------- docs/doc/pair.html | 4 ++-- docs/doc/paradigms.html | 6 +++--- docs/doc/pick.html | 13 +++++++------ 5 files changed, 33 insertions(+), 34 deletions(-) (limited to 'docs') diff --git a/docs/doc/oop.html b/docs/doc/oop.html index 66df070f..2e47476c 100644 --- a/docs/doc/oop.html +++ b/docs/doc/oop.html @@ -65,7 +65,7 @@

Objects

-

An object in BQN is simply a namespace: its fields and methods are variables in the namespace, and one of these can be accessed outside of the namespace with dot syntax if it's exported with . Unexported variables are instance-private in OOP parlance, meaning that they're only visible to the object containing them. They could be utilities, or hold state for the object. As an example, the object below implements the Tower of Hanoi puzzle with five disks. You can view the state (a list of disks occupying each of the three rods) with towerOfHanoi.View, or move the top disk from one rod to another with towerOfHanoi.Move.

+

An object in BQN is simply a namespace: its fields and methods are variables in the namespace, and a variable can be accessed outside of the namespace with dot syntax if it's exported with . Unexported variables are instance-private in OOP parlance, meaning that they're only visible to the object containing them. They could be utilities, or hold state for the object. As an example, the object below implements the Tower of Hanoi puzzle with five disks. You can view the state (a list of disks occupying each of the three rods) with towerOfHanoi.View, or move the top disk from one rod to another with towerOfHanoi.Move.

towerOfHanoi  {
   l  ¨500
   View  {𝕤
@@ -82,7 +82,7 @@
   }
 }
 
-

Two fields l and Transfer aren't exported, for two different reasons. l encodes the state of the tower, but it's often better to expose it with the function View instead to allow the internal representation to be changed freely. Transfer is just a utility function. While it's not dangerous to use outside of the object, there's no reason to expose it through towerOfHanoi's interface. If it's wanted in another place it should be moved to a common location.

+

Two variables l and Transfer aren't exported, for two different reasons. l encodes the state of the tower, but it's only exposed with the function View, which allows the internal representation to be changed freely. Transfer is just a utility function. While it's not dangerous to use outside of the object, there's no reason to expose it through towerOfHanoi's interface. If it's wanted in another place it should be moved to a common location.

Here are the results of a few applications of these functions.

    t  towerOfHanoi
     t.View@
@@ -101,14 +101,14 @@
   2 3 4   0 1  ⟨⟩ 
 

Classes

-

The object above is a singleton: there's just one of it, at least in the scope it occupies. It's often more useful to have a class that can be used to create objects. What we'll call a "class" is a namespace function, that is, a function that contains and so returns a namespace. It's very easy to convert a singleton object to a class: just add a no-op 𝕤 line to force it to be a function, and call it with @ when needed.

+

The object above is a singleton: there's just one of it, at least in the scope it occupies. It's often more useful to have a class that can be used to create objects. What we'll call a "class" is a namespace function, that is, a function that contains and so returns a namespace. It's very easy to convert a singleton object to a class: just add a no-op 𝕤 line to force it to be a function, and call it with @ when needed.

MakeStack  {𝕤
   st@
   Push{   st𝕩st}
   Pop {𝕤 rsst  sts  r}
 }
 
-

But there's no need to ignore the argument: often it's useful to initialize a class using one or two arguments. For example, the stack class above can be modified to use 𝕩 as an initial list of values for the stack.

+

But arguments don't have to be ignored: often it makes sense to use one or two arguments to initialize the object. For example, the stack class above can be modified to use 𝕩 as an initial list of values for the stack.

MakeStackInit  {
   st@
   Push{   st𝕩st}
@@ -116,7 +116,7 @@
   Push¨ 𝕩
 }
 
-

A stack is a particularly simple class to make because its state can be represented efficiently as a BQN value. Other data structures don't allow this, and will often require an extra Node class when they are implemented—see MakeQueue below.

+

A stack is a particularly simple class to make because its state can be represented efficiently as a BQN value. Other data structures don't allow this, and will often require an extra Node class in an implementation—see MakeQueue below.

Mutability

An object is one way to transform variable mutation into mutable data. These are two different concepts: changes which value is attached to a name in a scope, while mutable data means that the behavior of a particular value can change. But if a value is linked to a scope (for an object, the scope that contains its fields), then variable mutation in that scope can change the value's behavior. In fact, in BQN this is the only way to create mutable data. Which doesn't mean it's rare: functions, modifiers, and namespaces are all potentially mutable. The difference between objects and the operations is just a matter of syntax. Mutability in operations can only be observed by calling them. For instance F 10 or -_m could return a different result even if the variables involved don't change value. Mutability in an object can only be observed by accessing a member, meaning that obj.field or fieldobj can yield different values over the course of a program even if obj is still the same object.

Let's look at how mutability plays out in an example class for a single-ended queue. This queue works by linking new nodes to the tail t of the queue, and detaching nodes from the head h when requested (a detached node will still point to h, but nothing in the queue points to it, so it's unreachable and will eventually be garbage collected). Each node has some data v and a single node reference n directed tailwards; in a double-ended queue or more complicated structure it would have more references. You can find every mutable variable in the queue by searching for , which shows that t and h in the queue, and n in a node, may be mutated. It's impossible for the other variables to change value once they're assigned.

@@ -124,7 +124,7 @@ the{SetN{h𝕩}} Node{v𝕩ne SetN{n𝕩}} Push{t.SetN nNode 𝕩 tn} - Pop {𝕤vh.v{t𝕩}(e=)hh.nv} + Pop {𝕤vh.vhh.n{e=h?te;@}v} }

Unlike a stack, a node's successor isn't known when it's created, and it has to be set. You might be inclined to make n settable directly, but we'll get more mileage out of a setter function SetN. This allows us to create a pseudo-node e (for "empty") indicating there are no values in the queue. Because it has no .v field, if h is e then Pop gives an error (but in a real implementation you'd want to test explicitly instead in order to give an appropriate error message). In fact it doesn't have an n field, and essentially uses the queue head h instead. With this empty "node", the queue definition is straightforward. The only tricky part to remember is that if Pop removes the last node, resulting in e=h, then the tail has to be set to e as well, or it will keep pointing to the removed node and cause bugs.

@@ -137,7 +137,7 @@ Undo t.MovePop } -

This class composes a Tower of Hanoi with an undo stack that stores previous moves. To undo a move from a to b, it moves from b to a, although if you felt really fancy you might define Move in towerOfHanoi instead with 𝕊𝕩: 𝕊⌽𝕩.

+

This class composes a Tower of Hanoi with an undo stack that stores previous moves. To undo a move from a to b, it moves from b to a, although if you felt really fancy you might define Move in towerOfHanoi instead with an undo header 𝕊𝕩: 𝕊⌽𝕩.

It's also possible to copy several variables and only export some of them, with an export statement. For example, if I wasn't going to make another method called Move, I might have written ViewMove towerOfHanoi and then View. In fact, depending on your personal style and how complicated your classes are, you might prefer to avoid inline exports entirely, and declare all the exports at the top.

Self-reference

An object's class is given by 𝕊. Remember, a class is an ordinary BQN function! It might be useful for an object to produce another object of the same class (particularly if it's immutable), and an object might also expose a field class𝕤 to test whether an object o belongs to a class c with o.class = c.

@@ -145,14 +145,14 @@
IntrospectiveClass  {
   obj  {
     this@
-    SetThis  { !this=@  this𝕩 }
+    SetThis  { !this@  this𝕩 }
   }
   obj.setThis obj
 }
 
-

This is a pretty clunky solution, and exports a useless method SetThis (which gives an error if it's ever called). It would be possible for BQN to define a system value •this that just gets the namespace's value. It would work only at the top level, so it would have to be assigned (this•this) in order to use it in functions. This means it's always used before the namespace is done being defined, so a drawback is that it introduces the possibility that an object used in a program has undefined fields. The reason this isn't possible for objects without •this is that BQN's blocks don't have any sort of control flow, so that they always execute every statement in order. The namespace becomes accessible as a value once the block finishes, and at this point every statement has been executed and every field is initialized.

+

This is a pretty clunky solution, and exports a useless method SetThis (which gives an error if it's ever called). It would be possible for BQN to define a system value •this that just gets the namespace's value. It would work only at the top level, so it would have to be assigned (this•this) in order to use it in functions. This means it's always used before the namespace is done being defined, so a drawback is that it introduces the possibility that an object used in a program has undefined fields. Currently a namespace can only be created with all fields set: a block body doesn't have any sort of control flow other than the early exit ?, so it can only finish by executing every statement, including every field definition, in order.

Class members

-

As with this, giving a class variables that belong to it is a do-it-yourself sort of thing (or more positively, not at all magic (funny how programmer jargon goes the opposite way to ordinary English)). It's an easy one though, as this is exactly what lexical scoping does:

+

As with this, creating variables that belong to a class and not its objects is a do-it-yourself sort of thing (or more positively, not at all magic (funny how programmer jargon goes the opposite way to ordinary English)). It's an easy one though, as this is exactly what lexical scoping does:

staticClass  {
   counter  0
   {𝕤
diff --git a/docs/doc/order.html b/docs/doc/order.html
index 58ed2583..a75c2600 100644
--- a/docs/doc/order.html
+++ b/docs/doc/order.html
@@ -7,21 +7,21 @@
 

Ordering functions

BQN has six functions that order arrays as part of their operation (the comparison functions ≤<>≥ only order atoms, so they aren't included). These come in three pairs, where one of each pair uses an ascending ordering and the other uses a descending ordering.

The array ordering shared by all six is described last. For lists it's "dictionary ordering": two lists are compared one element at a time until one runs out, and the shorter one comes first in case of a tie. Operation values aren't ordered, so if an argument to an ordering function has a function or modifier somewhere in it then it will fail unless all the orderings can be decided without checking that value.

You can't provide a custom ordering function to Sort. The function would have to be called on one pair of cells at a time, which is contrary to the idea of array programming, and passing in a function with side effects could lead to implementation-specific behavior. Instead, build another array that will sort in the order you want (for example, by selecting or deriving the property you want to sort on). Then Grade it, and use the result to select from the original array.

Sort

-

You've probably seen it before. Sort Up () reorders the major cells of its argument to place them in ascending order, and Sort Down () puts them in descending order. Every ordering function follows this naming convention—there's an "Up" version pointing up and a "Down" version going the other way.

+

You've probably seen it before. Sort Up () reorders the major cells of its argument to place them in ascending order, and Sort Down () puts them in descending order. Every ordering function follows this naming convention—there's an "Up" version pointing up and a "Down" version going the other way.

↗️
     "delta""alpha""beta""gamma"
 ⟨ "alpha" "beta" "delta" "gamma" ⟩
 
      "δαβγ"
 "δγβα"
 
-

Sort Down always matches Sort Up reversed, . The reason for this is that BQN's array ordering is a total order, meaning that if one array doesn't come earlier or later than another array in the ordering then the two arrays match. Since any two non-matching argument cells are strictly ordered, they will have one ordering in and the opposite ordering in . With the reverse, any pair of non-matching cells are ordered the same way in and . Since these two results have the same major cells in the same order, they match. However, note that the results will not always behave identically because Match doesn't take fill elements into account (if you're curious, take a look at ¨0,"" versus ¨0,"").

+

Sort Down always matches Sort Up reversed, . The reason for this is that BQN's array ordering is a total order, meaning that if one array doesn't come earlier or later than another array in the ordering then the two arrays match. Since any two non-matching argument cells are strictly ordered, they will have one ordering in and the opposite ordering in . After the reverse, any pair of non-matching cells are ordered the same way in and . Since these two results have the same major cells in the same order, they match. However, note that the results will not always behave identically because Match doesn't take fill elements into account (if you're curious, take a look at ¨0,"" versus ¨0,"").

Grade

@@ -68,7 +68,7 @@ -

Grade is more abstract than Sort. Rather than rearranging the argument's cells immediately, it returns a list of indices (more precisely, a permutation) giving the ordering that would sort them.

+

Grade is more abstract than Sort. Rather than rearranging the argument's cells immediately, it returns a list of indices (more precisely, a permutation) giving the ordering that would sort them.

↗️
     l  "planet""moon""star""asteroid"
 ⟨ "planet" "moon" "star" "asteroid" ⟩
 
@@ -153,9 +153,9 @@
 

How does it work? First, let's note that l is a permutation: it contains exactly the numbers ↕≠l, possibly in a different order. In other words, ∧⍋l is ↕≠l. Permuting an array rearranges the cells but doesn't remove or duplicate any. This implies it's always invertible: given a permutation p, some other permutation q will have 𝕩 qp𝕩 for every 𝕩 of the right length. This would mean that while l transforms l to l, the inverse of l transforms l back into l. That's what we want: for each cell of l, the corresponding number in the inverse of l is what index that cell has after sorting.

But what's the inverse q of a permutation p? Our requirement is that 𝕩 qp𝕩 for any 𝕩 with the same length as p. Setting 𝕩 to ↕≠p (the identity permutation), we have (↕≠p) qp, because p⊏↕≠p is just p. But if p is a permutation then p is ↕≠p, so our requirement could also be written (p) qp. Now it's all coming back around again. We know exactly how to get q! Defining qp, we have qp (p)p p ↕≠p, and qp𝕩 (qp)𝕩 (↕≠p)𝕩 𝕩.

-

The fact that Grade Up inverts a permutation is useful in itself. Note that this applies to Grade Up specifically, and not Grade Down. This is because the identity permutation is ordered in ascending order. Grade Down would actually invert the reverse of a permutation, which is unlikely to be useful. So the ordinals idiom that goes in the opposite direction is actually not ⍒⍒ but ⍋⍒. The initial grade is different, but the way to invert it is the same.

+

The fact that Grade Up inverts a permutation is useful in itself. Note that this applies to Grade Up specifically, and not Grade Down. This is because the identity permutation is ordered in ascending order. Grade Down would invert the reverse of a permutation, which is unlikely to be useful. So the ordinals idiom that goes in the opposite direction is actually not ⍒⍒ but ⍋⍒. The initial grade is different, but the way to invert it is the same.

Stability

-

When sorting an array, we usually don't care how matching cells are ordered relative to each other (although it's possible to detect it by using fill elements carefully. They maintain their ordering). Grading is a different matter, because often the grade of one array is used to order another one.

+

When sorting an array, we usually don't care how matching cells are ordered relative to each other (although as mentioned above it's possible to detect it by using fill elements carefully. They maintain their ordering). Grading is a different matter, because often the grade of one array is used to order another one.

↗️
     t  > "dog"4, "ant"6, "pigeon"2, "pig"4 
 ┌─            
 ╵ "dog"    4  
@@ -189,9 +189,8 @@
 "210dcbaEDCBA"
 

Bins

-

There's also an APL Wiki page on this function, but be careful as the Dyalog version has subtle differences.

The two Bins functions are written with the same symbols and as Grade, but take two arguments instead of one. More complicated? A little, but once you understand Bins you'll find that it's a basic concept that shows up in the real world all the time.

-

Bins behaves like a search function with respect to rank: it looks up cells from 𝕩 relative to major cells of 𝕨. However, there's an extra requirement: the left argument to Bins is already sorted according to whichever ordering is used. If it isn't, you'll get an error.

+

Bins behaves like a search function with respect to rank: it looks up cells from 𝕩 relative to major cells of 𝕨. However, there's an extra requirement: the left argument to Bins must already be sorted according to whichever ordering is used. If it isn't, you'll get an error.

↗️
    56241  3
 Error: ⍋: 𝕨 must be sorted
 
@@ -208,10 +207,9 @@
 

A score of 565e7 sits between 578e7 and 553e7 at rank 3, 322e7 wouldn't make the list, 788e7 would beat everyone, and 627e7 would tie the high score but not beat it. The same principles apply to less spring-loaded things like character indices and line numbers (𝕨 is the index of the start of each line), or percentage scores and letter grades on a test (𝕨 is the minimum score possible for each grade). In each case, it's better to think of Bins not as a counting exercise but as finding "what bin" something fits into.

Array ordering

Most of the time you won't need to worry about the details of how BQN arrays are ordered. It's documented here because, well, that's what documentation does.

-

The array ordering defines some arrays to be smaller or larger than others. All of the "Up" ordering functions use this ordering directly, so that smaller arrays come earlier, and the "Down" ones use the opposite ordering, with larger arrays coming earlier. For arrays consisting only of characters and numbers, with arbitrary nesting, the ordering is always defined. If an array contains an operation, trying to order it relative to another array might give an error. If comparing two arrays succeeds, there are three possibilities: the first array is smaller, the second is smaller, or the two arrays match.

-

Comparing two atoms is defined to work the same way as the comparison functions ≤<>≥. Numbers come earlier than characters and otherwise these two types are ordered in the obvious way. To compare an atom to an array, the atom enclosing and then compared with the array ordering defined below. The result of this comparison is used except when the two arrays match: in that case, the atom is considered smaller.

-

Two arrays of the same shape are compared by comparing all their corresponding elements, in index order. This comparison can stop at the first pair of different elements (which allows later elements to contain operations without causing an error). If any elements were different, then they decide the result of the comparison. If all the elements matched, then by definition the two arrays match.

+

BQN's array ordering is an extension of the number and character ordering given by to arrays. In this system, any two arrays that have only numbers and characters for atoms can be compared with each other. Furthermore, some arrays that contain incomparable atoms (operations or namespaces) might be comparable, if the result of the comparison can be decided before reaching these atoms. Array ordering never depends on fill elements. If comparing two arrays succeeds, there are three possibilities: the first array is smaller, the second is smaller, or the two arrays match. All of the "Up" ordering functions use this ordering directly, so that smaller arrays come earlier, and the "Down" ones use the opposite ordering, with larger arrays coming earlier.

+

Comparing two atoms is defined to work the same way as the comparison functions ≤<>≥. Numbers come earlier than characters and otherwise these two types are ordered in the obvious way. To compare an atom to an array, the atom is enclosed and then compared with the array ordering defined below. The result of this comparison is used except when the two arrays match: in that case, the atom is considered smaller.

+

Two arrays of the same shape are compared by comparing all their corresponding elements, in index order. This comparison stops at the first pair of different elements (which allows later elements to contain operations without causing an error). If any elements were different, then they decide the result of the comparison. If all the elements matched, then by definition the two arrays match.

The principle for arrays of different shapes is the same, but there are two factors that need to be taken into account. First, it's not obvious any more what it means to compare corresponding elements—what's the correspondence? Second, the two arrays can't match because they have different shapes. So even if all elements end up matching one of them needs to come earlier.

-

BQN's array ordering is an extension of the number and character ordering given by to arrays. In this system, any two arrays consisting of only numbers and characters for atoms can be compared with each other. Furthermore, some arrays that contain incomparable atoms (operations) might be comparable, if the result of the comparison can be decided before reaching these atoms. Array ordering does not depend on the fill elements for the two arguments.

Let's discuss correspondence first. One way to think about how BQN makes arrays correspond is that they're simply laid on top of each other, lining up the first (as in ) elements. So a shape 4 array will match up with the first row of a shape 53 array, but have an extra element off the end. A simple way to think about this is to say that the lower rank array is brought up to a matching rank by putting 1s in front of the shape, and then lengths along each axis are matched up by padding the shorter array along that axis with a special "nothing" element. This "nothing" element will be treated as smaller than any actual array, because this rule recovers the "dictionary ordering" rule that a word that's a prefix of a longer word comes before that word. In the case of the shapes 4 and 53, if the three overlapping elements match then the fourth element comes from the first row and is present in the first array but not the second. So the shape 53 array would be considered smaller without even looking at its other four rows.

It can happen that two arrays of different shape have all matching elements with this procedure: either because one array's shape is the same as the other's but with some extra 1s at the beginning, or because both arrays are empty. In this case, the arrays are compared first by rank, with the higher-rank array considered larger, and then by shape, beginning with the leading axes.

diff --git a/docs/doc/pair.html b/docs/doc/pair.html index a3a3a33e..40d153e6 100644 --- a/docs/doc/pair.html +++ b/docs/doc/pair.html @@ -39,7 +39,7 @@ ⟨ 9 3 18 2 ⟩

Pair versus Couple

-

Enlist and Pair closely related to Solo and Couple, in that is equivalent to < and is equivalent to >. However, the result of is always a list (rank 1) while Solo or Couple return an array of rank at least 1.

+

Enlist and Pair are closely related to Solo and Couple, in that is equivalent to < and is equivalent to >. However, the result of is always a list (rank 1) while Solo or Couple return an array of rank at least 1.

↗️
    "abc"  "def"
 ┌─     
 ╵"abc  
@@ -56,7 +56,7 @@
     "abc"  "defg"
 ⟨ "abc" "defg" ⟩
 
-

The difference is that Couple treats the arguments as cells, and adds a dimension, while Pair treats them as elements, adding a layer of depth. Couple is a "flat" version of Pair, much like Cells (˘) is a flat version of Each (¨). Pair is more versatile, but—precisely because of its restrictions—Couple may allow more powerful array operations on the result.

+

The difference is that Couple treats the arguments as cells, and adds a dimension, while Pair treats them as elements, adding a layer of depth. Couple is a "flat" version of Pair, much like Cells (˘) is a flat version of Each (¨). Pair is more versatile, but—precisely because of its restrictions—Couple may allow more powerful array operations on the result.

Fill element

Enlist and Pair set the result's fill element, while list notation doesn't have to. So the following result is guaranteed:

↗️
    4  "a"5  "b"7
diff --git a/docs/doc/paradigms.html b/docs/doc/paradigms.html
index 5542f213..145de26c 100644
--- a/docs/doc/paradigms.html
+++ b/docs/doc/paradigms.html
@@ -9,13 +9,13 @@
 

This information doesn't tell you what tasks BQN is good for: after all, it turns out you can write an efficient compiler entirely using array programming, something many people assumed was impossible. Instead, it tells you what approaches you can take to writing programs, and how comfortable you'll find it to start using BQN—or how much you can use it to stretch your brain in new directions.

When programming in BQN, I almost always use array, tacit, and (slightly impure) functional styles, and encapsulate code in medium or large projects using namespaces. I sometimes use object-oriented or imperative programming in addition to these.

Typing

-

BQN is a dynamically typed language with a coarse type system that only distinguishes types when the difference is blindingly obvious. There is a single numeric type and a single unicode character type. A fast implementation such as CBQN will check to see when it can represent the data with a smaller type than the one offered by the language. BQN usually avoids implicit type conversion, with the exception that many primitives automatically convert atoms to unit arrays. The fact that a data value can be applied as a function to return itself could also be considered an implicit conversion.

+

BQN is a dynamically typed language with a coarse type system that only distinguishes types when the difference is blindingly obvious. There is a single numeric type and a single Unicode character type. A fast implementation such as CBQN will check to see when it can represent the data with a smaller type than the one offered by the language. BQN usually avoids implicit type conversion, with the exception that many primitives automatically convert atoms to unit arrays. The fact that a data value can be applied as a function to return itself could also be considered an implicit conversion.

BQN has no "pointer" or "reference" type, and uses automatic memory management. Its data types are immutable while operations and namespaces are mutable; mutable data can create reference loops, which the implementation must account for in garbage collection but the programmer doesn't have to worry about.

Dynamic types and garbage collection introduce overhead relative to a statically-typed or manually managed language. The impact of this overhead can be greatly reduced with array programming, because an array of numbers or characters can be stored as a single unit of memory and processed with functions specialized to its element type.

Styles

BQN is designed for array programming. The array is its only built-in collection type and it has many primitives designed to work with arrays.

-

BQN is okay for imperative programming. Blocks are lists of statements. Variables can be modified with , and while there are no truly global variables, lexical scoping allows variables at the top level of a file, which are similar (•Import with no left argument saves and reuses results, so that data can be shared between files by loading the same namespace-defining file in each). BQN doesn't directly support structured programming (which refers to a particular way to structure programs; it also doesn't have a Goto statement, the "unstructured" alternative when the term was coined). However, its first-class functions allow a reasonably similar imitation of control structures.

-

Functional programming is a term with many meanings. Using the terms defined in the functional programming document, BQN supports first-class functions and function-level programming, allows but doesn't encourage pure functional programming, and does not support typed functional programming. BQN uses lexical scope and has full support for closures. In this way BQN is very similar to Lisp, although it lacks Lisp's macro system.

+

BQN is okay for imperative programming. Blocks are lists of statements. Variables can be modified with , and while there are no truly global variables, lexical scoping allows variables at the top level of a file, which are similar (•Import with no left argument saves and reuses results, so that data can be shared between files by loading the same namespace-defining file in each). BQN doesn't directly support structured programming (which refers to a particular way to structure programs; it also doesn't have a Go-to statement, the "unstructured" alternative when the term was coined). However, its first-class functions allow a reasonably similar imitation of control structures.

+

Functional programming is a term with many meanings. Using the terms defined in the page on functional programming, BQN supports first-class functions and function-level programming, allows but doesn't encourage pure functional programming, and does not support typed functional programming. BQN uses lexical scope and has full support for closures. In this way BQN is very similar to Lisp, although it lacks Lisp's macro system.

BQN has excellent support for tacit or point-free programming, with trains and intuitive symbols for combinators making it much easier to work with (in my opinion) than other languages that support this style. It's near-universally considered a poor choice to implement entire programs in a tacit style, so this paradigm is best used as a small-scale tool within a style like functional or object-oriented programming.

BQN uses namespaces as modules to organize code; the only possible interaction with a module is by its exported variables. There doesn't seem to be a name for this paradigm, but there should be.

BQN supports object-oriented programming only incidentally. This is not as bad as it sounds, and programming with objects in BQN can often feel pretty similar to other object-based languages. The main differences are that objects don't have a this property to pass themselves into functions, and there's no built-in way to find the class of an object. There is also no support for inheritance, which is not unheard of in the object-oriented world.

diff --git a/docs/doc/pick.html b/docs/doc/pick.html index 275b623a..060dcdc1 100644 --- a/docs/doc/pick.html +++ b/docs/doc/pick.html @@ -6,7 +6,7 @@

Pick

Pick () chooses elements from 𝕩 based on index lists from 𝕨. 𝕨 can be a plain list, or even one number if 𝕩 is a list, in order to get one element from 𝕩. It can also be an array of index lists, or have deeper array structure: each index list will be replaced with the element of 𝕩 at that index, effectively applying to 𝕨 at depth 1.

-

With no 𝕨, monadic 𝕩 takes the first element of 𝕩 in index order, with an error if 𝕩 is empty.

+

The one-argument form is called First, and 𝕩 takes the first element of 𝕩 in index order, with an error if 𝕩 is empty.

While sometimes "scatter-point" indexing is necessary, using Pick to select multiple elements from 𝕩 is less array-oriented than Select (), and probably slower. Consider rearranging your data so that you can select along axes instead of picking out elements.

One element

When the left argument is a number, Pick gets an element from a list:

@@ -23,7 +23,7 @@ ¯2 "abc" 'b'
-

Making 𝕩 a list is only a special case. In general 𝕨 can be a list of numbers whose length is 𝕩's rank. So when =𝕩 is 1, 𝕨 can be length-1 list. For convenience, a number is also allowed, but not an enclosed number (which could be confused with the nested case).

+

Making 𝕩 a list is only a special case. In general 𝕨 can be a list of numbers whose length is 𝕩's rank. So when =𝕩 is 1, 𝕨 can be length-1 list. The case above where 𝕨 is a number is a simplification, but an enclosed number 𝕨 isn't allowed because it could be confused with the nested case described below.

↗️
    2,0  45
 ⟨ 2 0 ⟩
 
@@ -40,14 +40,14 @@ 1¯1 a 'j'
-

This applies even if 𝕩 is a unit. By definition it has rank 0, so the only possible value for 𝕨 is the empty list. This extracts an enclosed element, and returns an atom unchanged—the atom is promoted to an array by enclosing it, then the action of Pick undoes this. But there's rarely a reason to use this case, because the monadic form First accomplishes the same thing.

+

𝕩 can even be a unit. By definition it has rank 0, so the only possible value for 𝕨 is the empty list. This extracts an enclosed element, and returns an atom unchanged—the atom is promoted to an array by enclosing it, then the action of Pick undoes this. But there's rarely a reason to use this case, because the monadic form First accomplishes the same thing.

↗️
    ⟨⟩  <'a'
 'a'
     ⟨⟩  'a'
 'a'
 

First

-

With no left argument, is called First, and performs a slight generalization of Pick with a default left argument 0¨𝕩. For a non-empty array it returns the first element in index order.

+

With no left argument, is called First, and is the same as Pick with a default left argument 0¨𝕩. For a non-empty array it returns the first element in index order.

↗️
     <'a'
 'a'
      "First"
@@ -55,9 +55,10 @@
      4251
 ⟨ 0 0 0 0 ⟩
 
-

If 𝕩 is empty then First results in an error, like Pick.

-↗️
     ""
+

And if 𝕩 is empty then First results in an error.

+↗️
     ""
 Error: ⊑: Argument cannot be empty
+
      π
 Error: ⊑: Argument cannot be empty
 
-- cgit v1.2.3