Dfn: Difference between revisions

Jump to navigation Jump to search
1,078 bytes added ,  12:27, 2 November 2020
no edit summary
No edit summary
Tags: Mobile edit Mobile web edit
No edit summary
Line 19: Line 19:
           ⍵*÷⍺          ⍝ result
           ⍵*÷⍺          ⍝ result
       }</source>
       }</source>
=== Error-guards ===
Dyalog APL dfns support error-guards for processing errors by error codes.<ref>[https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Error%20Guards.htm Error Guards] – Dyalog APL.</ref>
In the following example, there are two error-guards for the error code 11 (DOMAIN ERROR):<ref>[https://help.dyalog.com/latest/#Language/Errors/APL%20Errors.htm#APLErrors APL Error Messages and Codes] – Dyalog APL.</ref>
<source lang=apl>
Gravity←{
    G←6.6743E¯11      ⍝ gravitational constant
    11::'N/A'          ⍝ second DOMAIN ERROR: return 'N/A'
    11::∇⍎¨⍵          ⍝ first DOMAIN ERROR: maybe the argument is a vector of strings?
    G×⍵[1]×⍵[2]÷⍵[3]*2 ⍝ the argument is a vector of numbers
}
      ⍝ Calculate gravity force between the Earth and the Sun
      Gravity '1.99e30' '5.97e24' '1.50e11'
3.524119391E22
      Gravity 1.99e30 5.97e24 1.50e11
3.524119391E22
      Gravity 1.99e30 5.97e24 0  ⍝ trigger division by zero
N/A
</source>


== External links ==
== External links ==
Line 30: Line 51:
* [https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Dynamic%20Functions%20and%20Operators.htm Dyalog]
* [https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Dynamic%20Functions%20and%20Operators.htm Dyalog]
* [https://www.gnu.org/software/apl/apl.html#Section-3_002e7 GNU APL]
* [https://www.gnu.org/software/apl/apl.html#Section-3_002e7 GNU APL]
== References ==
<references/>


{{APL syntax}}[[Category:Kinds of functions]][[Category:Defining functions]]
{{APL syntax}}[[Category:Kinds of functions]][[Category:Defining functions]]

Navigation menu