Hello.
I have noticed that the macro APPLY in PS expands to a call to the function's apply method with an invariable “this” as its first argument (thisArg, per http://ecma-international.org/ecma-262/5.1/ #sec-15.3.4.3). When the function is a method of an object, this may result in incorrect code. Consider:
(lambda (some-vector start del-count &rest elts) ... (apply (@ some-vector splice) start del-count elts) ... )
=>
(function (someVector, start, delCount) { var elts = []; for (var i120 = 0; i120 < arguments.length - 3; i120 += 1) { elts[i120] = arguments[i120 + 3]; }; ... someVector.splice.apply(this, [start, delCount].concat(elts)); ... });
Whereas, to be correct, the apply part should go like
someVector.splice.apply(someVector, [start, delCount].concat (elts));
Please find attached a patch which makes APPLY recognize property accessors in the function argument, separate them into object and method, and pass the object to the method's apply. For cases which require more fine-grained control, the patch adds an APPLY-TO macro which provides for a completely custom thisArg.
There's also a separate patch with a couple of unit tests.
Yours, — B. Smilga.