A similar pattern, Memo, or Memoization, stores state as well, but it is often used as a program-speed optimization. If a time-consuming operation has a limited number of common inputs and outputs, the most common ones (or all of them) can be stored in a hashtable. When called again with the same inputs, it first checks the hashtable and if it finds them, it returns the previous output without recalculating it.
I imagine a Memento pattern could be used for performance as well - instead of doing all the reverse-calculations for a reverse state change, just restore from the previous state. Some functions are one-way, so there is no undo unless you store the previous state.
You could use a Memento pattern to memoize a periodic, or symmetric function like sine. Calculate all the values from 0-180 degrees, then go backwards through them to get the negative values from 180-360. Better yet, calculate values from 0-90, then go backwards through those values to get 90-180, forwards for 180-270, and backwards from 270-360.
Ctrl-Z in Word, or the undo function of any software is likely implemented by using the memento pattern, or in some cases, possibly by a reverse of the function that made each change. In the second case, the history of which functions were called would be mementos, so I suppose the memento pattern is always used for undo.
What you seem to be describing is Lazy Evaluation. Computations to be performed when the result is needed, rather than when it appears in the source code.
In Haskell, this is done by hiding these computations behind monadic abstractions. In C++, the abstractions are similar, but more explicit, and partially hidden behind overloaded operators and expression templates.
Similarly, your cited example of "Greenspunning" of a Lisp-like construct in C is not an antipattern, but rather a data-driven lazily-evaluated DSL, and seems, actually, to be one of the most common patterns of an FFI for Lisp and Scheme interpreters (especially in ECL, Chicken, tinyscheme and others), since C lacks the means to construct and pass unexecuted functions as data.
You will notice that these patterns do not appear in languages which have first-class function objects.
Best Answer
If the delegation (and the default parameters filled in) are part of the function's contract, for example, if the DocString says
then I refer to these as convenience overloads or convenience methods as they simply save the user some typing but don't do anything the user couldn't have done otherwise.
If the fact that the function simply delegates is not made public, then it is just an arbitrary implementation detail and probably does not deserve a special name.
I've picked this term up from the official Java documentation where it is used quite often.
A related idiom is to have a bunch of overloads for some
public
methoddoSomething
that do nothing more than determining some parameters to then delegate to aprivate
methoddoSomethingImpl
. This is something different as the user is not aware of the existence of thedoSomethingImpl
method (and couldn't possibly call it). I have heard thedoSomethingImpl
be referred to as “worker method” or “workhorse” but those are probably very colloquial terms.