迭代过程中的固定数量和固定规则

Fixed number and fixed rule in iterative process

我正在阅读 1.2 Procedures and the Processes They Generate 的 SICP。

计算阶乘的线性迭代过程

(define (factorial n)
  (fact-iter 1 1 n))

(define (fact-iter product counter max-count)
  (if (> counter max-count)
      product
      (fact-iter (* counter product)
                 (+ counter 1)
             max-count)))

迭代次数:
产品<---专柜·产品
计数器 <--- 计数器 + 1

然后说明:

At each step, all we need to keep track of, for any =n=, are the current values of the variables product, counter, and max-count. We call this an iterative process. In general, an iterative process is one whose state can be summarized by
1) a fixed number of state variables,
2) together with a fixed rule that describes how the state variables should be updated as the process moves from state to state
3) and an (optional) end test that specifies conditions under which the process should terminate. In computing n!, the number of steps required grows linearly with n. Such a process is called a linear iterative process.

参考 1) 固定号码 2) 固定规则和 3) 可选结束测试

当我可以确认 max-count 是 3) 可选的结束测试时。但我不确定修复编号和固定规则。

如果fixed number是counter那么fixed rule就是product=counter * product,这种情况下counter不固定,是counter += 1

如果固定数是计数器,固定规则是counter + 1,那么它们就省略了产品的更大规则,太琐碎了。

固定号码和固定规则是什么?

在此上下文中,"fixed number" 个变量意味着存在 有限的 个变量,在流程开始时预先知道 - 我们只有三个: product countermax-count。这与递归过程形成对比,递归过程将在堆栈帧中的每个过程调用拥有这三个变量的新副本。

第二点是相关的:a"fixed rule"指的是在程序的递归步骤中我们直接调用fact-iter,执行完就没什么可做的了:in other换句话说,它在尾部位置