js-on-sx: js-apply-fn unwraps __callable__ before invoking

This commit is contained in:
2026-04-23 23:06:24 +00:00
parent 1079004981
commit d7ad7172aa

View File

@@ -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.