I’m experiencing an issue regarding upvars. Its application is an update to the Streams library, but I’ll keep it as simple as possible for now. I do hope that someone will find a solution to the version I’m presenting here.
One use of upvars is as a parameter to be used in an embedded script. A well-known example is with the for
block, e.g.:
Another example is in the “Iteration, composition” library:
In both cases the upvar (i , or #) is maintained by the HOF-block (for
, or cascade
) and used by the embedded command (change
) or function (+
), respectively. And it works very well.
But if the evaluation of the script is somehow postponed, an issue may arise. I made a block new applicator
:
… that will create an anonymous HIGHER ORDER FUNCTION (HOF), applying an embedded function on an index; the latter corresponds with the number of times the HOF was called.
So, for example:
Stand-alone, this works well. But if I create another HOF with the same block, something weird happens:
I can change the name of any upvar, so I can repair it:
… but for a library function, I don’t want the user to have to remember changing upvar names from the default.
So this is my request: can anyone think of a way to prevent this mix-up of upvars?