Hello my second question here might be very hard.
I am asking for something "magical", if i define a function g and i call it inside a function f, how can g have information about the outer function f?
To be more precise: Suppose there is a unknown number of functions {f1,f2,f3,...}, how can g know in which Function it was evaluated?
Pseudocode:
f1[g] "--inside-of-g-->" f1
f3[g] "--inside-of-g-->" f3
I have an Idear how to work on this problem, but it works not in every case.
EDIT:
ok, i wanted to reduce my problem to the relevant point, but i can also explain you, what i exactly want to do with it.
I want to build up a function myTicks[plotRange]
that generates Axes-Ticks for a Plot the way i want. My first function works like this:
Plot[Sin[x], {x,0,10}, Ticks->{myTicks[{0,10}, StepSize-> 0.5], Automatic}]
Now i want to change the plotRange of myTicks to an optional argument like:
MyTicks[plotRange_:Automatic, opt:OptionsPattern[]] := Module[{},
If[plotRange =!= Automatic, Range[plotRange〚1〛, plotRange〚2〛,
OptionValue[StepSize]], (* magical lookup for the PlotRange of the Plot *)]]
So now it should be possible to call myTicks without giving the actual PlotRange of the outer Plotfunction.
I hope that i did not confuse you more.
EDIT2: here goes my simple Solution that doesn't work in general for me:
My simple Solution is a little hackish and works not in every case:
In:
g[arg_: "default"] := Module[{read, expr},
read = NotebookRead[EvaluationCell[]];
expr = ToExpression[ReplaceAll[read, Cell[x__, y__] :> x],
StandardForm, Hold];
Print[expr];
Sin[arg]
]
f[g[2]]
Out:
Hold[f[g[2]]]
f[Sin[2]]
In this Case expr holds enough Information to work with, so that one could filter out the functionname f, but there is a big problem with this solution:
It only works, if the function g appears explicitly in the EvaluationCell. something like:
h[a_] := a*f[g[2]];
h[2]
wont work (expr == Hold[h[2]])
A second problem is, that when the EvaluationCell holds more than one line, it gets very complicated to filter out in wich line the function was called. Just think about if the function g is called more than once in the EvaluationCell.
So my solution is not very satisfying in general.
A good example of a functionality like this, is the build-in-Mathematica function OptionValue. So there must be a better way to do this!