求值策略
(由正常次序求值跳轉過嚟)
主要策略
編輯舉例說明,想像家陣要行以下噉嘅表達式[1]
def double x = (plus x x) def average x y = (divide (plus x y) 2)
用正常次序求值(normal-order evaluation)嘅話,會做嘅嘢係「吓吓都郁手拆咗最左嗰個子程序先」→
(double (average 2 4)) => (plus (average 2 4) (average 2 4)) => (plus (divide (plus 2 4) 2) (average 2 4)) => ...
而用應用次序求值(applicative-order evaluation)嘅話,會做嘅嘢係「吓吓都郁手拆咗最入嗰個子程序先」→
double (average 2 4) => double (divide (plus 2 4) 2) => double (divide 6 2) => ...
睇埋
編輯攷
編輯- ↑ Abelson, Harold; Sussman, Gerald Jay (1996). Structure and Interpretation of Computer Programs (Second ed.). Cambridge, Massachusetts: The MIT Press. p. 21-22.
- ↑ Normal, Applicative and Lazy Evaluation. Kevin Sookocheff.