4,493
edits
(Disambiguate from dfns workspace) |
|||
Line 14: | Line 14: | ||
4 | 4 | ||
3 {⍵*÷⍺} 27 ⍝ ⍺th root | 3 {⍵*÷⍺} 27 ⍝ ⍺th root | ||
3 | 3</source> | ||
=== Default left arguments === | |||
Assignment to <source lang=apl inline>⍺</source> is unusual in that the entire statement is only executed if the dfn is called monadically:<ref>[https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Default%20Left%20Argument.htm Default Left Argument] – Dyalog APL.</ref> | |||
<source lang=apl> | |||
root←{ | root←{ | ||
⍺←2 ⍝ square root by default | ⍺←2 ⍝ square root by default | ||
⍵*÷⍺ ⍝ result | |||
}</source> | |||
=== Guards === | |||
Guards provide dfns with support for basic flow control.<ref>[https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Guards.htm Guards] – Dyalog APL.</ref> This is a multiline dfn with a conditional result: | |||
<source lang=apl> | |||
root←{ | |||
⍺=0:0 ⍝ return zero if zeroth root | ⍺=0:0 ⍝ return zero if zeroth root | ||
⍵*÷⍺ ⍝ result | ⍵*÷⍺ ⍝ result |