4,493
edits
No edit summary |
|||
Line 37: | Line 37: | ||
A tradfn can be [[niladic function|niladic]] which causes it to behave syntactically like an array. However, every time its name is referenced, it will run to create a result (if any). Such methods are often used to return a cache or as an entry point for the user. | A tradfn can be [[niladic function|niladic]] which causes it to behave syntactically like an array. However, every time its name is referenced, it will run to create a result (if any). Such methods are often used to return a cache or as an entry point for the user. | ||
Some dialects have let the header syntax explicitly specify that a function is [[ambivalent]] by enclosing the left argument name in curly braces (for example <source lang=apl inline>result←{left} Function right</source>) while others treat all functions that specify a left argument name as ambivalent and leave it up to the programmer to check for the presence of a value. | |||
Some dialects allow a tradfn to return a function value as result. The returned function will replace the function and its arguments (if any) in the calling expression: | |||
<source lang=apl> | |||
∇ Fn←Apply name | |||
[1] :If name≡'plus' | |||
[2] Fn←+ | |||
[3] :ElseIf name≡'times' | |||
[4] Fn←× | |||
[5] :EndIf | |||
∇ | |||
3(Apply'plus')4 | |||
7 | |||
3(Apply'times')4 | |||
12 | |||
</source> | |||
== A+ == | == A+ == |