4 (define (k2 rf ng prv arg)
5 (let ((al (length arg)))
7 (apply rf (append prv arg))
10 (k2 rf (- ng al) (append prv arg) x))
11 (error "too many arguments")))))
16 ;; ----------------------------------------
18 (define r1 (k 1)) ;; returns a lambda needs 2
19 (define r2 (r1 2)) ;; returns a lambda needs 1
22 (define r3 (k 1 2)) ;; returns a lambda needs 1
25 (k 1 2 3) ;; returns 6 right away
29 (k 1 2 3 4) ;; above 3 are all errors
31 ;; ----------------------------------------
32 ;; pitfall: need to know the target function arity, any ideas?