微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么 DrRacket 似乎将此识别为尾调用?

如何解决为什么 DrRacket 似乎将此识别为尾调用?

考虑这个片段:

#lang racket

(define (f i)
  (if (> i 5)
      0
      (+ 1 (f (+ 1 i)))))

这里,对 f调用不在尾部位置,当我调试时,我看到表单的堆栈越来越大

(+ ...)
(f ...)
(f ...)
(f ...)
(f ...)

这是预料之中的。但是,当我将鼠标悬停在最后一行的开头时,会出现一个浅紫色箭头并指向函数定义的开头。如果我正确理解文档,它表示尾部位置。我错过了什么?

解决方法

最后一行的形式相对于 /** * When using the quantity selector,this can be used to decrease the quantity (be ensuring it won't be lower than 1) */ },{ key: '_decreaseQuantity',value: function _decreaseQuantity(event,target) { target.nextElementSibling.value = Math.max(parseInt(target.nextElementSibling.value) - 1,1); } /** * When using the quantity selector,this can be used to increase the quantity */ },{ key: '_increaseQuantity',value: function _increaseQuantity(event,target) { target.previousElementSibling.value = parseInt(target.previousElementSibling.value) + 1; } /** * Make sure the quantity does not go below when manually changed */ },{ key: '_validateQuantity',value: function _validateQuantity(event,target) { target.value = Math.max(parseInt(target.value) || 1,1); } }]); return ProductVariants; }(); 处于尾部位置。然而,对 f 的递归调用不是:如果您将鼠标悬停在 f 上,您将看到一个淡蓝色箭头,它告诉您它与函数绑定的 f 相同.这是显示这两件事的屏幕截图:

arrows

所有的 f 形式及其后件都在尾部。 (if ...) 与函数定义的 f 相同,但不在尾部。

,

当你移动到 B 时,你看到 A ➯ B。这意味着你可以在 A 中找到 B 的定义。

enter image description here

enter image description here

当你移动到 A 时,你会看到 A ➯ B。你可以看到变量绑定的出现。

enter image description here

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。