AnsweredAssumed Answered

How do you refer to functions whose names are arguments to other functions?

Question asked by RolfNoyer on Sep 7, 2017
Latest reply on Sep 7, 2017 by RolfNoyer

Hi everyone,


This is either a really easy question or a hard question and I am not sure which!


I want to write a custom function — let’s call it _foobar_ —  that takes as one of its arguments another function — let’s call that one _varfunc_.


So _foobar_ needs to call the function whose name is the value of the variable _varfunc_.


My understanding is that this type of function is referred to as a “higher-order” function. I understand the concept but not how to do it in FileMaker.


To take a trivial but concrete example, suppose I want to write a custom function that takes as an argument either the function “Lower” or the function “Upper”, and applies that function to _text_.  If the only conceivable values for _varfunc_ are "Upper" and "Lower" then I simply write


foobar (text; varfunc) =

Case (varfunc = "Lower";

          Lower (text) ;

          Upper (text))


But in the case I am concerned with I don’t want to have to limit the range of possible values for _varfunc_; I want it to be the case that, whatever _varfunc_ is,  foobar (text; varfunc) returns the result of applying the function whose name is passed as the argument _varfunc_ to be applied to _text_. (Obviously the real examples that I am dealing with in my application are more complex, but this is the general problem).


So in principle I would expect something like


foobar (text; varfunc) =

VARFUNC (text)


where by "VARFUNC" I want the value of _varfunc_ treated as a function name.


I thought using the Evaluate function might work but I don’t know how; I tried various options with quotation marks and so forth but it did not work out in an obvious way for me.


It seems like the answer ought to be either: do this little thing and it will work fine, or no, you can’t do that with FileMaker at all.


Please advise!

Thank you!!