Good question. The broader context of what I am doing is implementing my own general framework for working with reasonably large quantities of time-series data. Let’s take the case where I have an object with
f4. In my framework, this is essentially a set of instructions for building a new time-series from (possibly multiple) existing time-series. We apply
f1 to some data,
f2 to the output of
f1 and so on. I could combine them all into
f as you suggest, but then when building, I’d need to start from the beginning every time. The vision in my head that I’m trying to implement instead iterates down from
f4, and at each stage it stops and checks whether the time-series it is trying to build has already been built before and saved in my database (nothing fancy, just binary files using the file-system for lookup). It might turn out that in this particular case,
f2 is quite expensive, and I’ve already built it before. So my routine would ideally iterate down from
f4 looking for pre-built series, stop at
f2 and say a ha, we’ve already done this one before, read in that series from the database, then apply
f4 to it.
I’m am certainly open to suggestions about better ways to implement this vision. This is actually my second attempt at such a framework. My first relied almost entirely on multiple dispatch, and ultimately ended up being too unwieldy (but I was fairly new to the language when I did it). One reason I settled on functions is that my needs from the framework can change quite rapidly, and being able to just write new functions and pass them in is a relatively simple solution for someone of my abilities (I’m reasonably experienced with Julia now, but have essentially zero CS background, ie entirely self-taught, so there are some alarming gaps in my knowledge).
Often it does work out as you say - there is a small family of functions and I use many different parameterizations. In this case I have typically just generated an anonymous function for each parameterization I needed and passed it round. The limitation to this (for me anyway) is that I can’t utilize my trick of saving expensive transformations to the hard-drive, since I can’t generate any consistent naming conventions from anonymous functions. So my more recent solution to this was to generate fixed function names for the parameterizations that currently interest me via meta-programming.
In other cases, each transformation is its own expensive, individual function.
Thanks for taking the time to read this thread and think about my problem. I’ll look into functor objects (which I’d never heard of before - see aforementioned alarming gaps), and anything else you might recommend based on the above.