Hyperators: Difference between revisions
m (→Syntax Glitch) |
|||
Line 93: | Line 93: | ||
==Syntax Glitch== | ==Syntax Glitch== | ||
For technical reasons I'm still working on, the Syntax Analyzer does not correctly handle the case of a Hyperator with two Hyperands and two Operands and where the | For technical reasons I'm still working on, the Syntax Analyzer does not correctly handle the case of a Hyperator with two Hyperands and two Operands and where the '''right hyperand''' is a '''function or operator''' and the '''right operand''' is a '''function'''. For example, if <apll>dhdo</apll> is an example of this kind of Hyperator: | ||
<apll><pre> | <apll><pre> |
Revision as of 11:15, 1 July 2019
Object Orders
The sequence of objects: Arrays, Functions, and Operators appear in ascending order with the property that each later object consumes one or two of the earlier objects and produces an object in the sequence one order less. For example, a Function takes Array(s) and produces an Array; an Operator takes Array(s) and/or Function(s) and produces a (derived) Function.
Hyperators extend this sequence by one:
- a Hyperator has one or two Hyperands (any of Arrays, Functions, and/or Operators) and yields ...
- an Operator which has one or two Operands (any of Arrays and/or Functions) and yields ...
- a Function which has zero, one, or two Arguments (Arrays) and yields...
- an Array.
That is, in the object hierarchy:
Order | Object | Options | User-Defined Function Example |
---|---|---|---|
0 | Array | ||
1 | Function | 0, 1, 2 Arguments |
∇Z← fn0 ∇Z← fn1 R ∇Z←L fn2 R |
2 | Operator | 0, 1, 2 Arguments and 1 or 2 Operands |
∇Z← (LO op01) ∇Z← (LO op11) R ∇Z←L (LO op21) R ∇Z← (LO op02 RO) ∇Z← (LO op12 RO) R ∇Z←L (LO op22 RO) R |
3 | Hyperator | 0, 1, 2 Arguments and 1 or 2 Operands and 1 or 2 Hyperands |
∇Z← (LO (LH hy011)) ∇Z← (LO (LH hy111)) R ∇Z←L (LO (LH hy211)) R ∇Z← (LO (LH hy021) RO) ∇Z← (LO (LH hy121) RO) R ∇Z←L (LO (LH hy221) RO) R ∇Z← (LO (LH hy012 RH)) ∇Z← (LO (LH hy112 RH)) R ∇Z←L (LO (LH hy212 RH)) R ∇Z← (LO (LH hy022 RH) RO) ∇Z← (LO (LH hy122 RH) RO) R ∇Z←L (LO (LH hy222 RH) RO) R |
Each Function, Operator, and Hyperator may have any of its lower order objects as its Arguments, Operands, or Hyperands, respectively. Missing from the above table due to lack of space is the option for both Operators and Hyperators of using a Jot (∘) for one or both Operands or Hyperands to indicate a missing element. Also missing is the usual function header enhancements such as Axis Operator, Optional Left Argument, Shy Result, Lists of Names in the Arguments, etc.
Anonymous Functions
Following the lead of John Scholes[1], Anonymous Functions are extended to Hyperators by defining three new special symbols:
- ⍺⍺⍺ represents the Left Hyperand
- ⍵⍵⍵ represents the Right Hyperand
- ∇∇∇ represents the Hyperator itself
Scoping
Similar to Operators, Hyperators have short right scope and for the same reason: so as to reduce the number of surrounding parentheses required to limit its right scope. However, unlike Operators, Hyperators must have short left scope, too. Here's why:
Because Hyperators may take an operator as a hyperand, and in particular as a left hyperand, we need a way to pass both a function left operand and an operator left hyperand. In particular, how can we pass + as a left operand and / as a left hyperand to a Hyperator?
One's first choice might be to code
+/mhmo
where mhmo is a Monadic Hyperand Monadic Operand hyperator. However, if Hyperators have long left scope, then the left hyperand in the above example is +/ and there is no left operand specified.
Another possibility is to use
+(/)mhmo
but this violates the APL2 rule on Redundant Parentheses ("Parentheses surrounding a primitive or constructed name, a character string (enclosed in quotation marks), or an already parenthesized expression are always redundant."[2]), so that example is equivalent to the previous one.
Only if Hyperators have short left scope can we pass a function as a left operand and an operator as the left hyperand to a Hyperator as in the example +/mhmo.
FWIW, there is another example with this scoping rule that also illustrates a change in Binding Strength in NARS2000: Vector Notation (a.k.a. Numeric Strands).
In the same example as above with a Monadic Hyperand Monadic Operand hyperator, how can we pass (say) a 12 as a left operand and a 34 as a left hyperand? This can be accomplished with
12 34 mhmo
because the rules for Binding Strength used by NARS2000 dictate that Vector Notation has a lower Binding Strength than both a right operand to its operator and either hyperand to its hyperator. In these three cases, the scope is short which is interpreted by NARS2000 as extracting the number nearest to the operator/hyperator from the numeric strand and using it for the operand/hyperand.
This yields several interesting cases:
- A dyadic operator written as <aplcl>… dop 1 2 3 4</aplcl> is interpreted as having a right operand (short right scope) of <aplcl>1</aplcl> and a right argument of <aplcl>2 3 4</aplcl>.
- A hyperator written as either <aplcl>1 2 3 4 mhmo</aplcl> or <aplcl>1 2 3 4 mhdo …</aplcl> is interpreted as having a left hyperand (short left scope) of <aplcl>4</aplcl> and a left operand (long left scope) of <aplcl>1 2 3</aplcl>.
- A dyadic hyperator written as <aplcl>… dhmo 1 2 3 4</aplcl> is interpreted as having a right hyperand (short right scope) of <aplcl>1</aplcl> and a right argument of <aplcl>2 3 4</aplcl>.
- A dyadic hyperator written as <aplcl>… dhdo 1 2 3 4</aplcl> is interpreted as having a right hyperand (short right scope) of <aplcl>1</aplcl>, a right operand (short right scope) of <aplcl>2</aplcl>, and a right argument of <aplcl>3 4</aplcl>.
To reduce confusion, use parentheses such as <aplcl>(LO (LH dhdo 1) 2) 3</aplcl>.
Abbreviations:
- <aplcl>dop</aplcl> Dyadic Operator
- <aplcl>mhmo</aplcl> Monadic Hyperand Monadic Operand Hyperator
- <aplcl>mhdo</aplcl> Monadic Hyperand Dyadic Operand ...
- <aplcl>dhmo</aplcl> Dyadic Hyperand Monadic Operand ...
- <aplcl>dhdo</aplcl> Dyadic Hyperand Dyadic Operand ...
Syntax Glitch
For technical reasons I'm still working on, the Syntax Analyzer does not correctly handle the case of a Hyperator with two Hyperands and two Operands and where the right hyperand is a function or operator and the right operand is a function. For example, if dhdo is an example of this kind of Hyperator:
+-dhdo×÷ 23 SYNTAX ERROR +-dhdo×÷ 23 ∧
To get this case to parse correctly, use parentheses as in
(+-dhdo×÷) 23
All other cases of this kind of Hyperator are parsed correctly without needing to resort to extra parentheses.
References
- Hyperators, Dyalog APL Dfns, https://dfns.dyalog.com/n_hyperators.htm
- Hyperators, Dyalog APL Example, https://dfns.dyalog.com/n_cf.htm
- Hyperators, Dyalog APL Example, https://dfns.dyalog.com/n_cond.htm