diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-09-18 10:31:31 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-09-18 10:31:58 -0400 |
| commit | 9cdca8be1ea02d095752b514e86bb57f7c63a8f0 (patch) | |
| tree | 1d5131723b697dd9a3f4ac97018d24aa989509f2 /docs | |
| parent | 5649a16965af692dd24c5a823cf0dba6257c8eed (diff) | |
Grammar
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/doc/based.html | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/docs/doc/based.html b/docs/doc/based.html index 031c9572..58a183f5 100644 --- a/docs/doc/based.html +++ b/docs/doc/based.html @@ -9,7 +9,7 @@ <p>This page explains how BQN's array model (christened "based" <a href="https://dl.acm.org/doi/abs/10.1145/586656.586663">in 1981</a>) differs from the models used by existing APL dialects, and why the choice was made to discard APL's "everything is an array" dictum. If you're not wondering what the difference is, and don't think everything should be an array, then you can probably just read about BQN's <a href="types.html">type system</a> instead.</p> <p>If you're an array programmer then I have bad news for you. My thesis here is that APL took a wrong turn around 1981 when it extrapolated the excellent, but limited, flat array model of APL\360 to the ill-founded nested array model and the rigorous but clumsy boxed array model. Make that two wrong turns, I guess. Simultaneously. Anyway, if you've been brought up in either of these array models, then the best thing to do when starting BQN is to throw out your existing ideas about array depth and nesting (but don't worry too much: the fundamental concept of an array as a rectangular collection of data still holds!). If you'd like to ponder the relationship of BQN to APL later, that's great, but trying to initially understand BQN in terms of APL or J will just cause confusion.</p> <h2 id="starting-from-atoms">Starting from atoms</h2> -<p>APL tends to define its data by starting with the array and then looking downwards in depth at what it contains. The based array model, as the name suggests, starts with at the foundations, which in BQN are called "atoms". There are five types of atom, which together with the array type give the six types a value can have in BQN. Based means being yourself, and an atom's <em>not</em> an array.</p> +<p>APL tends to define its data by starting with the array and then looking downwards in depth at what it contains. The based array model, as the name suggests, starts at the foundations, which in BQN are called "atoms". There are five types of atom, which together with the array type give the six types a value can have in BQN. Based means being yourself, and an atom's <em>not</em> an array.</p> <p>An atom has <a href="depth.html">depth</a> 0, and doesn't inherently have a shape. However, primitives that expect an array promote atoms by enclosing them to get a scalar containing the atom. Rank and shape both do this, so an atom can be considered to have the same dimensions as a scalar: rank 0 and shape <code><span class='Bracket'>⟨⟩</span></code>.</p> <p>Atoms are displayed as plain values, while boxed atoms (that is, depth-1 scalar arrays) are shown with an array display.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MyAgICAjIEF0b20KPDMgICAjIEFycmF5CiczJyAgIyBBdG9t&run">↗️</a><pre> <span class='Number'>3</span> <span class='Comment'># Atom @@ -41,7 +41,7 @@ <h2 id="building-arrays">Building arrays</h2> <p>Arrays in BQN, like nearly all data structures in modern programming languages, are an <a href="https://en.wikipedia.org/wiki/Inductive_type">inductive type</a>. That means that an array can be constructed from existing values, but can't contain itself (including recursively: an array always has finite depth). To construct the type of all BQN values inductively, we would say that atoms form the base case, and arrays are an inductive case: an array is a shaped collection of existing BQN values. For an array programmer, this is of course the easy part.</p> <h2 id="versus-the-nested-array-model">Versus the nested array model</h2> -<p>The <a href="https://aplwiki.com/wiki/Array_model#Nested_array_theory">nested array model</a> of NARS, APL2, Dyalog, and GNU APL can be constructed from the based model by adding a rule: a scalar array containing an atom is equivalent to that atom. The equivalents of atoms in nested array theory are thus called "simple scalars", and they are considered arrays but share the same characteristics of BQN atoms. Nested arrays don't form an inductive type, because simple scalars contain themselves.</p> +<p>The <a href="https://aplwiki.com/wiki/Array_model#Nested_array_theory">nested array model</a> of NARS, APL2, Dyalog, and GNU APL can be constructed from the based model by adding a rule: a scalar array containing an atom is equivalent to that atom. The equivalents of atoms in nested array theory are thus called "simple scalars", and they are considered arrays but share the characteristics of BQN atoms. Nested arrays don't form an inductive type, because simple scalars contain themselves.</p> <p>Nested array theory can seem simpler to use, because the programmer never has to worry about simple scalars being enclosed the wrong number of times: all these encloses have been identified with each other. For example, <code><span class='String'>'</span><span class='Value'>abcd</span><span class='String'>'</span><span class='Value'>[</span><span class='Number'>2</span><span class='Value'>]</span></code> returns a character while BQN's <code><span class='Number'>2</span><span class='Function'>⊏</span><span class='String'>"abcd"</span></code> returns a scalar containing a character. However, these issues usually still appear with more complex arrays: <code><span class='String'>'</span><span class='Value'>ab</span><span class='String'>'</span> <span class='Number'>1</span> <span class='String'>'</span><span class='Value'>ef</span><span class='String'>'</span><span class='Value'>[</span><span class='Number'>2</span><span class='Value'>]</span></code> (here spaces are used for stranding) is not a string but an enclosed string!</p> <p>A property that might warn about dangerous issues like this is that nested array theory tends to create <em>inversions</em> where the depth of a particular array depends on its rank (reversing the normal hierarchy of depth→rank→shape). A 1-character string has depth 1, but when its rank is reduced to 0, its depth is reduced as well.</p> <p>In some cases nested array theory can remove a depth issue entirely, and not just partially. Most notable is the <a href="../problems.html#search-function-depth">search function result depth</a> issue, in which it's impossible for a search function in BQN to return an atomic number because it always returns an array. Nested array theory doesn't have this issue since a scalar number is "just a number", and more complicated arrays can't cause problems because a search function's result is always a numeric array. The other half of the problem, about the non-principal argument depth, is only partly hidden, and causes problems for example when searching for a single string out of a list of strings.</p> |
