Should I include all functions, function inputs, and raw inputs in a higher level function signature, or is it better to just inherit some of these input values from scope?
a. What’s the cutoff? Just have the function inherit all variables?
Is the second line the right way to define a subset of some function?
Is there a better way to name derivative variables like \frac{da}{dN}? Maybe a unicode fraction symbol that won’t be evaluated?
Maybe I’m misunderstanding, but let’s make a simpler example:
julia> f(a, b) = a/(a+b)
julia> g(a, b) = f(a, b)^2
julia> h(p, a, b) = p(a, b)^2
julia> f(1, 2)
0.3333333
julia> g(1, 2)
0.1111111
julia> h(f, 1, 2)
0.11111111
julia> h(+, 1, 2)
9
A function can simply use another function that is defined outside it (or indeed inside it but that’s for later). That’s what happens for g, it can just use f, no declarations needed.
If you need to be able to change which function is called inside your function, you can give it as an argument, like h does here. Putting the function argument first is a bit of a convention.
When it comes to inheriting variables from scope, this is called global variables and it’s a bit of a code smell, it will probably lower your performance. The exception is constants (like indeed those functions). If you notice you’re sending some constant into every function you may want to declare it a constant and remove it from the arguments.
If you always want to specialize on the given function then yes. In your concrete example however I believe that Julia will anyway specialize on p, since you directly call p in the function body. See the performance docs for more info.