简体   繁体   English

在球拍(Scheme)中的arguments.callee?

[英]arguments.callee in Racket (Scheme)?

I need the feature arguments.callee of JavaScript in Racket (Scheme). 我需要在Racket(Scheme)中使用JavaScript的功能arguments.callee Do you know how? 你知不知道怎么?

Here, an example in JavaScript 这是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: 您无法在Racket中以动态方式获取当前正在执行的函数,但您仍然可以在Racket中的问题中实现该函数,只需为函数命名即可:

(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. 由于某种原因,你可能觉得你需要arguments.callee的动态性,并且可能通过其他机制实现这个目标,但是因为你没有为你认为必要的原因提供任何背景在你的问题中,我无法猜测其他机制可能是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM