# Dfn: Difference between revisions

Jump to navigation
Jump to search

m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com") |
No edit summary |
||

Line 6: | Line 6: | ||

Wikipedia includes a thorough treatment of [[Wikipedia:dfns|dfns]]. | Wikipedia includes a thorough treatment of [[Wikipedia:dfns|dfns]]. | ||

== Examples == | |||

<source lang=apl> | |||

{⍵*0.5} 16 ⍝ square root | |||

4 | |||

3 {⍵*÷⍺} 27 ⍝ ⍺th root | |||

3 | |||

⍝ Multiline dfn with optional left parameter | |||

root←{ | |||

⍺←2 ⍝ square root by default | |||

⍵*÷⍺ ⍝ result | |||

} | |||

</source> | |||

== External links == | == External links == | ||

* [[wikipedia:Direct function|Direct function]] | * [[wikipedia:Direct function|Direct function]] | ||

=== Tutorials === | === Tutorials === | ||

* APL Cultivation: [https://chat.stackexchange.com/rooms/52405/conversation/lesson-2-diving-into-functions-in-apl Diving Into Functions in APL] | * APL Cultivation: [https://chat.stackexchange.com/rooms/52405/conversation/lesson-2-diving-into-functions-in-apl Diving Into Functions in APL] | ||

* Mastering Dyalog: [https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf#page=174 page 174] | * Mastering Dyalog: [https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf#page=174 page 174] | ||

=== Documentation === | === Documentation === | ||

* [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] |

## Revision as of 08:34, 2 August 2020

A **dfn** (contraction of **direct function** or **dynamic function**, pronounced "dee fun") is an alternative way to define a function and operator, invented by John Scholes. A dfn operator can also be called a **dop** (pronounced "dee op").

John Scholes was responsible for numerous presentations and publications on and about dfns, and until his passing he maintained the dfns website.

As of 2020, dfns are fully implemented in Dyalog APL, NARS2000, ngn/apl, dzaima/APL, and partially in GNU APL, although not all dialects implement lexical scoping, in contrast to the dynamic scoping of tradfns. In other words, a dfn cannot "see" locals of its caller, but can see locals of its definer.

Wikipedia includes a thorough treatment of dfns.

## Examples

```
{⍵*0.5} 16 ⍝ square root
4
3 {⍵*÷⍺} 27 ⍝ ⍺th root
3
⍝ Multiline dfn with optional left parameter
root←{
⍺←2 ⍝ square root by default
⍵*÷⍺ ⍝ result
}
```

## External links

### Tutorials

- APL Cultivation: Diving Into Functions in APL
- Mastering Dyalog: page 174

### Documentation