Returning functions from functions: TRADFNS vs DFNS
Posted: Thu Nov 24, 2022 10:54 pm
Tradfns allow you to return functions, but dfns don't. What's the history and reasoning for this distinction?
Apologies if this is discussed somewhere on the Forum or in the documentation. This can be quite a useful feature! [P.S. This is a contrived, simple example. Its usefulness is in more complex cases.]
See also the APL Wiki: https://aplwiki.com/wiki/Defined_function_(traditional)
Code: Select all
⎕FX 'R←TESTT N' ':IF N=1 ⋄ R←+ ⋄ :ELSE ⋄ R←- ⋄ :ENDIF'
2 (TESTT 1)3
5
2 (TESTT 0)3
¯1
TESTD←{ ⍵=1: + ⋄ -} ⍝ Or try _←+ etc..
2 (TESTD 1)3
SYNTAX ERROR
TESTD[0] TESTD←{⍵=1:+ ⋄ -}
∧
See also the APL Wiki: https://aplwiki.com/wiki/Defined_function_(traditional)