I am having trouble writing a function that takes parameters. One of the parameter values ββis a function. I have to get this value, but do not value it. I tried everything that I could think of, but so far nothing worked.
Basically, to illustrate this, I tried:
SetAttributes[Foo, HoldRest]; Options[Foo] = {Blah -> None} Foo[x_, OptionsPattern[]] := Module[{blah}, blah = OptionValue[Automatic, Automatic, Blah, Hold]; . . .
Then when I have:
func[a_, b_, c_] := a + b + c;
I would like to call Foo with:
Foo[2, Blah -> func[1, 2, 3]]
And let the "blah" variable (inside Foo) not be evaluated, i.e. blah = func [1, 2, 3].
Thanks for the help!
Edit:
For reasons that are too long for development, I cannot use RuleDelayed (:>). I am trying to write a function that will be in a package used by other people who really do not know Mathematica, so they do not have a clue what:> there is. Using rules (->) to specify options and their values ββis the standard way, and they are familiar with it.
So, to illustrate again, let's say I'm trying to write a number generator function that takes a function that generates an actual number as one of its options:
Options[GenerateNumbers] = {GeneratorFunction -> None}; GenerateNumbers[n_, OptionsPattern[]] := Module[{func}, func = OptionValue[GeneratorFunction]; Table[func, {n}] ] ]
Now, if I call this function with values ββas follows:
GenerateNumbers[5, GeneratorFunction -> RandomReal[10]]
It will return a list of 5 numbers that are the same, since RandomReal [10] is evaluated once, and not at each iteration of the table. I want to prevent this. The problem is more complicated, but it is in this respect.
Thanks!