为什么 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