Your assumption’s party right. As you probably noticed, my first ASObjC script (post #13) is just a revamp of my right-to-left vanilla script from post #10, with ObjC arrays and methods used instead of vanilla where there are more than two items.
In the vanilla scripts, the script-object-within-a-handler idea offers three advantages (to my way of thinking):
- The script object’s properties can be “referenced” to allow faster access to the vanilla list items.
- The recursive part of the only-partially recursive process can be contained within the main handler.
- The lists and the precalculated r and m values can be held in local properties instead of having to be passed or recalculated with each recursion or held in globals or global properties outside the main handler.
Point 1, as you say, doesn’t apply with the ObjC arrays. Point 2 is a largely a matter of my own personal preference. Point 3 is connected with point 2, but is also relevant with regard to the amount of work the script has to do. Your rewrite passes two extra parameters AND recalculates r and m on every call to the recursive handler. I’d therefore expect it to be a little slower than my script. And it is, on my machine. With nine items, it’s taking about six seconds longer than mine this morning. But mine’s taking a fair bit longer than it did yesterday, so the difference between the scripts’ times may actually be less under optimal conditions.
Now that’s interesting! But the difference is far less dramatic for me. 117 seconds as opposed to 134 (this morning). Still, that’s a lot more than I’d have expected until you mentioned it.