From d7ad7172aa37e837dd559224e0b41a210178020a Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 23 Apr 2026 23:06:24 +0000 Subject: [PATCH] js-on-sx: js-apply-fn unwraps __callable__ before invoking --- lib/js/runtime.sx | 49 +++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index 72d0b735..edd52b62 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -58,29 +58,32 @@ js-apply-fn (fn (fn-val args) - (cond - ((= (len args) 0) (fn-val)) - ((= (len args) 1) (fn-val (nth args 0))) - ((= (len args) 2) (fn-val (nth args 0) (nth args 1))) - ((= (len args) 3) (fn-val (nth args 0) (nth args 1) (nth args 2))) - ((= (len args) 4) - (fn-val (nth args 0) (nth args 1) (nth args 2) (nth args 3))) - ((= (len args) 5) - (fn-val - (nth args 0) - (nth args 1) - (nth args 2) - (nth args 3) - (nth args 4))) - ((= (len args) 6) - (fn-val - (nth args 0) - (nth args 1) - (nth args 2) - (nth args 3) - (nth args 4) - (nth args 5))) - (else (apply fn-val args))))) + (let + ((callable (if (and (dict? fn-val) (contains? (keys fn-val) "__callable__")) (get fn-val "__callable__") fn-val))) + (cond + ((= (len args) 0) (callable)) + ((= (len args) 1) (callable (nth args 0))) + ((= (len args) 2) (callable (nth args 0) (nth args 1))) + ((= (len args) 3) + (callable (nth args 0) (nth args 1) (nth args 2))) + ((= (len args) 4) + (callable (nth args 0) (nth args 1) (nth args 2) (nth args 3))) + ((= (len args) 5) + (callable + (nth args 0) + (nth args 1) + (nth args 2) + (nth args 3) + (nth args 4))) + ((= (len args) 6) + (callable + (nth args 0) + (nth args 1) + (nth args 2) + (nth args 3) + (nth args 4) + (nth args 5))) + (else (apply callable args)))))) ;; Minimal string->number for the slice. Handles integers, negatives, ;; and simple decimals. Returns 0 on malformed input.