I need the feature arguments.callee
of JavaScript in Racket (Scheme). Do you know how?
Here, an example in JavaScript
function makeFactorialFunc() {
return function(x) {
if (x <= 1)
return 1;
return x * arguments.callee(x - 1);
};
}
I need the feature arguments.callee
of JavaScript in Racket (Scheme). Do you know how?
Here, an example in JavaScript
function makeFactorialFunc() {
return function(x) {
if (x <= 1)
return 1;
return x * arguments.callee(x - 1);
};
}
You cannot get the currently executing function in a dynamic way in Racket, but you can certainly still implement the function in your question in Racket, just by giving the function a name:
(define (make-factorial-func)
(define (func x)
(if (<= x 1)
1
(* x (func (- x 1)))))
func)
It’s possible that you feel like you need the dynamic-ness of arguments.callee
for some reason, and it might be possible to achieve that goal through some other mechanism, but seeing as you don’t provide any context for why you think it’s necessary in your question, I can’t guess as to what that other mechanism might be.