Array notation design considerations: Difference between revisions

Jump to navigation Jump to search
m
Line 66: Line 66:


Value expressions could be evaluated in the newly established namespace (similar to expressions in <syntaxhighlight lang=apl inline>:Namespace</syntaxhighlight> scripts), or in the surrounding scope (similar to inline expressions in [[wikipedia:JavaScript|JavaScript]]'s object notation). It was envisioned that a main usage of the literal notation would be to collect existing values into a namespace, and evaluating inside the new namespace would force the use of <syntaxhighlight lang=apl inline>##.</syntaxhighlight> to fetch values in the surrounding scope. In a departure from JavaScript, it was found most natural that such intermediate assignments be local to the value expression, similar to assignments in dfns. Global assignment is still available using <syntaxhighlight lang=apl inline>⎕THIS.name←value</syntaxhighlight>, just as in dfns.
Value expressions could be evaluated in the newly established namespace (similar to expressions in <syntaxhighlight lang=apl inline>:Namespace</syntaxhighlight> scripts), or in the surrounding scope (similar to inline expressions in [[wikipedia:JavaScript|JavaScript]]'s object notation). It was envisioned that a main usage of the literal notation would be to collect existing values into a namespace, and evaluating inside the new namespace would force the use of <syntaxhighlight lang=apl inline>##.</syntaxhighlight> to fetch values in the surrounding scope. In a departure from JavaScript, it was found most natural that such intermediate assignments be local to the value expression, similar to assignments in dfns. Global assignment is still available using <syntaxhighlight lang=apl inline>⎕THIS.name←value</syntaxhighlight>, just as in dfns.
After publication of the formal proposal,<ref name=formprop/> Peter Mikkelsen, a then recently hired [[Dyalog Ltd]] employee<ref>[[Dyalog Ltd]]. [https://www.dyalog.com/meet-team-dyalog.htm#Peter Meet Teem Dyalog: Peter]. Retrieved May 2nd, 2023.</ref>, pointed out an inconsistency between value expressions in namespace and vector notation:
<syntaxhighlight lang=apl inline>g←1 ⋄ (a:g←2 ⋄ b:g)</syntaxhighlight> would make <syntaxhighlight lang=apl inline>(a:2 ⋄ b:1)</syntaxhighlight> but <syntaxhighlight lang=apl inline>g</syntaxhighlight> remains <syntaxhighlight lang=apl inline>1</syntaxhighlight>
while
<syntaxhighlight lang=apl inline>g←1 ⋄ (g←2 ⋄ g)</syntaxhighlight> would make <syntaxhighlight lang=apl inline>(2 ⋄ 2)</syntaxhighlight> updating <syntaxhighlight lang=apl inline>g</syntaxhighlight> to be <syntaxhighlight lang=apl inline>2</syntaxhighlight>.
Because of this, the specification was changed on May 5, 2023 to follow JavaScript; that assignments inside value expressions then affect the surrounding scope. Auto-localisation of temporary variables used in building the value can then be achieved by wrapping the expression in an anonymous [[dfn]].


== Timeline ==
== Timeline ==

Navigation menu