define
是
不同的
一个函数的顶层和内部。当你不能
定义
在边A
if
你可以放
如果
在表达式的内部
定义
:
这完全可以:
(define function1 (if (list? (first t1)) >= >))
(define function2 (if (list? (last t1)) <= <))
使用
let
也可以,但是只有在关闭时,您才能:
(let ([function1 (if (list? (first t1)) >= >)]
[function2 (if (list? (last t1)) <= <)])
;; use function1 and function2 here
)
;; function1 and function2 no longer exists here
与本地相同
定义
:
(let () ;; this is a function called right away
;; these are local define
(define function1 (if (list? (first t1)) >= >))
(define function2 (if (list? (last t1)) <= <))
;; use function1 and function2 here
)
;; function1 and function2 no longer exists here
这只是一种奇特的写作方式:
(let ()
(letrec ([function1 (if (list? (first t1)) >= >)]
[function2 (if (list? (last t1)) <= <)])
;; use function1 and function2 here
)
;; use function1 and function2 here
)
这个
让
在上一个例子中是多余的,因为前一个例子有多余的。