I have the following procedure to add three numbers:
(define add-3 (lambda (x y z) (+ x y z)))
(add-3 100 200 300)
; 600
When converting it to a curried function, it reduces to something like the following,
(apply (lambda args1
(apply add-3 (cons 100 args1)))
'(200 300))
; 600
My question is how does the above further reduce? For example, if I substitute in the list args1
=(200 300)
I get the following:
(apply (lambda args1
(apply add-3 (cons 100 args1)))
'(200 300))
(apply
(apply add-3 (cons 100 '(200 300))))
But that gives me ar arity mismatch
, so I must be doing something wrong in the reduction/substitution. What would be the proper way to do that?
I suppose a more direct way to ask this is how does the following simplification occur?
(apply (lambda args (apply add-3 args)) '(100 200 300))
; 600
; ... how do we get here?
(apply add-3 '(100 200 300))
; 600
For context: https://stackoverflow.com/a/68038585/651174.