目前正在学习 Racket Guide,参考网站链接为https://docs.racket-lang.org,同时在了解 lambda 函数。虽然对其实用性的解释很清晰,但我还不确定这些函数的执行顺序。以下是指南中的一个例子:
(define (twice f v)
(f (f v)))
(define (make-add-suffix s2)
(lambda (s) (string-append s s2)))
(twice (make-add-suffix "!") "hello")
这里对 twice
的函数调用被认为是评估为 "hello!!"
。下面是我猜测的评估过程:
(twice (make-add-suffix "!") "hello")
((make-add-suffix "!") ((make-add-suffix "!") "hello")
((make-add-suffix "!") (string-append "hello" "!"))
(string-append (string-append "hello" "!") "!")
(string-append "hello!" "!")
"hello!!"
这是一个准确的评估吗,还是我漏掉了什么重要的部分?