Passing a User-Defined Function as a Argument
3 posts
• Page 1 of 1
Passing a User-Defined Function as a Argument
Consider a dyadic user-defined function x Dy y which produces a result. Is there a way to pass the function Dy to another function as an argument? For example, if a monadic function Gg F1 requires function Dy to operate, is there a way to put Dy in the argument F1?
- REMINGTON30
- Posts: 22
- Joined: Fri Aug 11, 2017 2:17 pm
Re: Passing a User-Defined Function as a Argument
To answer your question directly, what you could do is create a namespace
ns←⎕NS'Dy'and pass the namespace as an argument or a part of an argument to Gg. Within Gg you could then call
arg.DyA problem is that if Dy had dependencies then inside the namespace above represented by arg there would be none of them. No doubt there are even more perverse ways to do it but the straightforward APL way is to make Gg an operator rather than a function. Operators take functions as arguments (operands) which can be called from within 'though they actually operate in the environment where they reside.
.
Gg←{
...
z←⍺⍺ ⍵ ⍝ runs Dy
...
}
Dy Gg F1
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Passing a User-Defined Function as a Argument
Thanks Phil. I will read the Dyalog documentation on user-defined operators and try that method.
- REMINGTON30
- Posts: 22
- Joined: Fri Aug 11, 2017 2:17 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group