cwebber pushed a commit to branch compile-to-js-merge
in repository guile.

commit 6f777154571480be2c01de3a7ad56e44611f4166
Author: Ian Price <[email protected]>
AuthorDate: Tue Jun 16 23:19:11 2015 +0100

    Implement apply correctly
---
 module/language/js-il/runtime.js | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/module/language/js-il/runtime.js b/module/language/js-il/runtime.js
index c9bf8ee..c14fbe4 100644
--- a/module/language/js-il/runtime.js
+++ b/module/language/js-il/runtime.js
@@ -288,8 +288,16 @@ scheme.is_true = function (obj) {
 };
 
 // Builtins
-var apply = function(self, k, f, arg) {
-    return f.fun(f.freevars, k, arg);
+var apply = function(self, k, f) {
+    var args = Array.prototype.slice.call(arguments, 3);
+    var tail = args.pop();
+
+    while (scheme.is_true(scheme.primitives["pair?"](tail))) {
+        args.push(tail.car);
+        tail = tail.cdr;
+    };
+
+    return f.fun.apply(f.fun, [f,k].concat(args));
 };
 
 var values = function(self, k) {

Reply via email to