Merge operators: Background
---------------------------
Classic APL lacks a general, non-procedural  way to express the "triadic" funct-
ion: "THESE items at THOSE positions in THIS array".  For example: "Asterisks at
the vowel positions in the alphabet".

Rather,  it  compels us to use a 3-stage _procedure_  and requires us to name an
intermediate subject array:

    [1] Name the subject array,                 ⍝ THIS ← ...
    [2] Mutate the array, using its name,       ⍝ THIS[THOSE]←THESE
    [3] Dereference the name for the result.    ⍝ ... THIS

(muse:

    Ideally, the language should never force us into naming the results of expr-
    essions. Better that we choose to name things only in order to create mental
    abstractions that are easier to work with.  For example, the following three
    code fragments are equivalent and each reducible by the  language  evaluator
    to the syntax tree on the right:

    (+/⍵)÷⍴⍵                                    ⍝
                                                ⍝        ┌───┼─┐
    sum←+/⍵ ⋄ num←⍴⍵  ⋄ sum÷num                 ⍝        ├─┐ ÷ ├─┐
                                                ⍝      ┌─┤ ⍵   ⍴ ⍵
    sum←+/ ⋄ num←⍴ ⋄ (sum ⍵)÷num ⍵              ⍝      + /

    Sound bite: Names allow us to chop up our program into mind-sized chunks.

    This approach is quite different from that of "variable-centric"  languages,
    where names must be declared to reserve storage locations and otherwise par-
    ticipate in the mechanics of evaluation.
)

Larg vs Rarg
------------
With indexed assignment, the "old" array is on the left and the "new" values are
on the right:

    OLD[⍳3]←'NEW'

A [merge] operator tends to save on parentheses if we arrange for the new value,
which might well be named or literal, to occur on the left.

Perhaps more important than saving parentheses is the impact of  argument  order
on ease of comprehension. Reading an expression (from left to right) seems to be
less disruptive if the modification (new value) is to the left:  merges are then
applied  as  refinements to the result of the expression developed further along
the line.

    old (sel merge) new         ⍝ say: "Old with sel[ected items] set to new".
vs:                               ¯¯¯¯                            ¯¯¯
    new (sel merge) old         ⍝ say: "New at sel[ection] in old".
                                  ¯¯¯¯
The second vocalisation appears (to JMS) to be preferable.

Merge is closely related to J's "amend":
http://www.jsoftware.com/help/dictionary/d530n.htm

See also: at

Back to: contents

Back to: Workspaces