User | Kudos |
---|---|
11 | |
7 | |
3 | |
2 | |
2 |
There! I said it 😎.
The problem
Here's a simple vim that replaces ',' with '.' in a string (half the world uses ',' as decimal separator):
To support 1D arrays we have to (ouch) duplicate the code:
To support 2D arrays, we need yet another duplicate:
So, to support scalars, 1D arrays and 2D arrays, we get:
I don't advocate nD (n>2) arrays, but duplicate code is undesirable. And this is just a trivial example.
You typically run into the lack of malleable recursion when you do serialization (to\from string, (un)flattening, to\from variant) very quickly.
Recursive malleable VIs
If we could call the vim in the .vim, we wouldn't have any duplication:
So what's stopping recursive malleable VIs?
Well, there's a 'minor' issue of infinite recursion.
There are 2 relatively simple ways to deal with this.
1) Limit the nesting level and break caller if it's reached.
We don't need 9D arrays, and certainly not 256D arrays.
2) Check if the .vim prototype has been used before and break caller if it is.
Let's say the .vim "V" is called with a string 'A'. V" turns 'A' into an array, that in a for loop call 'V' again.
That would be a use case for normal VI recursion (calls, managed at runtime), but it shouldn't be possible with malleable recursion (inlined code).
At least not at first. The compiler could inline each prototype and when called repetitively, use normal recursion. But that would be next level, and maybe not even desirable.
The scalar string input is simply not a stable input for this malleable VI. It will always result in infinite recursive compiled code. So, this should break the caller.
Of course, it should be perfectly legal to have a disabled type specialization case that calls the same prototype. As long as it's not actually compiled, that's perfectly valid:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.