Function axis: Difference between revisions

Jump to navigation Jump to search
153 bytes added ,  22:08, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (General editing for GNU discussion)
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 1: Line 1:
{{Built-in|Function axis|[ax]}} is a special syntax which modifies the behavior of a function, for example <source lang=apl inline>⌽[2]</source> to [[Rotate]] along the second [[axis]]. Axis specification was a feature of [[Iverson notation]] and was ubiquitous in early APLs; many newer APLs which adhere to [[leading axis theory]] reject the use of axis specification in favor of the [[Rank operator]] because it is a fully general operator while the behavior of functions with axis must be defined for each function separately. However, [[GNU APL]] implements the syntax and extends it so it applies to all user-defined functions.
{{Built-in|Function axis|[ax]}} is a special syntax which modifies the behavior of a function, for example <source lang=apl inline>⌽[2]</syntaxhighlight> to [[Rotate]] along the second [[axis]]. Axis specification was a feature of [[Iverson notation]] and was ubiquitous in early APLs; many newer APLs which adhere to [[leading axis theory]] reject the use of axis specification in favor of the [[Rank operator]] because it is a fully general operator while the behavior of functions with axis must be defined for each function separately. However, [[GNU APL]] implements the syntax and extends it so it applies to all user-defined functions.


== Functions ==
== Functions ==
Line 29: Line 29:


== Generalisation ==
== Generalisation ==
GNU APL generalises function axis to all functions, and beyond cases that refer to one or more argument axes. The axis works like an additional argument, which the function can use in any way. For example, <source lang=apl inline>⌹[ax] M</source> computes the [[wikipedia:QR factorization|QR factorization]] of <source lang=apl inline>M</source> with the [[comparison tolerance]] of <source lang=apl inline>ax</source>. Here, <source lang=apl inline>ax</source> is not an axis at all, and there's no direct connection between this monadic usage of Domino and its non-axis meaning of [[Matrix inverse]]. Thus there is no value for <source lang=apl inline>ax</source> such that <source lang=apl inline>f[ax]</source> is the same as <source lang=apl inline>f</source>, which is usually the case for existing axis definitions (not scalar functions). Much like the left argument of [[Circular]] (<source lang=apl inline>○</source>), The GNU APL specific File Input Output [[system function]] (<source lang=apl inline>⎕FIO</source>) uses the bracket axis syntax as a function selector, as does the [[wikipedia:SQL|SQL]] interface function (<source lang=apl inline>⎕SQL</source>). Some of the options for <source lang=apl inline>⎕SQL</source> take additional parameters as subsequent elements of the array inside the brackets. Similarly, the [[wikipedia:regular expression|regular expression]] interface (<source lang=apl inline>⎕RE</source>) uses [[character]] "axes" as flags for the regular expression engine, where [[Dyalog APL]] uses a [[dyadic operator]], [[Variant]] (<source lang=apl inline>⍠</source>), for analogous functionality.
GNU APL generalises function axis to all functions, and beyond cases that refer to one or more argument axes. The axis works like an additional argument, which the function can use in any way. For example, <source lang=apl inline>⌹[ax] M</syntaxhighlight> computes the [[wikipedia:QR factorization|QR factorization]] of <source lang=apl inline>M</syntaxhighlight> with the [[comparison tolerance]] of <source lang=apl inline>ax</syntaxhighlight>. Here, <source lang=apl inline>ax</syntaxhighlight> is not an axis at all, and there's no direct connection between this monadic usage of Domino and its non-axis meaning of [[Matrix inverse]]. Thus there is no value for <source lang=apl inline>ax</syntaxhighlight> such that <source lang=apl inline>f[ax]</syntaxhighlight> is the same as <source lang=apl inline>f</syntaxhighlight>, which is usually the case for existing axis definitions (not scalar functions). Much like the left argument of [[Circular]] (<source lang=apl inline>○</syntaxhighlight>), The GNU APL specific File Input Output [[system function]] (<source lang=apl inline>⎕FIO</syntaxhighlight>) uses the bracket axis syntax as a function selector, as does the [[wikipedia:SQL|SQL]] interface function (<source lang=apl inline>⎕SQL</syntaxhighlight>). Some of the options for <source lang=apl inline>⎕SQL</syntaxhighlight> take additional parameters as subsequent elements of the array inside the brackets. Similarly, the [[wikipedia:regular expression|regular expression]] interface (<source lang=apl inline>⎕RE</syntaxhighlight>) uses [[character]] "axes" as flags for the regular expression engine, where [[Dyalog APL]] uses a [[dyadic operator]], [[Variant]] (<source lang=apl inline>⍠</syntaxhighlight>), for analogous functionality.


GNU APL additionally gives user-defined functions, both [[dfn]]s and [[tradfn]]s, access to the bracket axis syntax, again while permitting its use for any purpose. For example, the [[root]] function could be implemented as a monadic function with axis specifying the degree, rather than as a dyadic function. In a dfn, the value given via axis notation is denoted <source lang=apl inline>χ</source>:
GNU APL additionally gives user-defined functions, both [[dfn]]s and [[tradfn]]s, access to the bracket axis syntax, again while permitting its use for any purpose. For example, the [[root]] function could be implemented as a monadic function with axis specifying the degree, rather than as a dyadic function. In a dfn, the value given via axis notation is denoted <source lang=apl inline>χ</syntaxhighlight>:
<source lang=apl>
<source lang=apl>
       Root←{⍵*÷χ}
       Root←{⍵*÷χ}
       Root[3]8
       Root[3]8
2
2
</source>
</syntaxhighlight>
{{Works in|[[GNU APL]]}}
{{Works in|[[GNU APL]]}}
Or as a tradfn, indicating axis notation in the header line:
Or as a tradfn, indicating axis notation in the header line:
Line 43: Line 43:
   r←y*÷ax
   r←y*÷ax
</source>
</syntaxhighlight>
{{Works in|[[GNU APL]]}}
{{Works in|[[GNU APL]]}}


Navigation menu