As a footnote to Chris Page’s excellent post in January, which I have just read with interest:
http://lists.apple.com/archives/applescript-users/2016/Jan/msg00152.html
First, a minor point, where Chris’s example used an assignment to bind x to 0,
I notice in myself a slight preference for using properties of the script object, here initially rewriting Chris’s example to:
Then, more generally, I am, FWIW, finding it useful, when I want more composable AppleScript, to delegate script-wrapping to a couple of higher order functions. Something like the mReturn function in this AppleScript definition of a dot product as essentially:
sum(zipWith(my product, xs, ys))
https://rosettacode.org/wiki/Dot_product#AppleScript
or the mClosure in this more obviously stretched experiment with expressing set comprehensions in functionally composed AppleScript: https://rosettacode.org/wiki/List_comprehensions#AppleScript
One variant on Chris’s example might then be (if we draw on an mClosure library function): mClosure(my next, {x:0, n:n}) set its x to (its x) + (its n) set inc to incrementBy(3) {inc's next(), inc's next(), inc's next()} -- Handler -> Record -> Script on mClosure(f, recBindings) property closure : recBindings
|