Module lambda表达式内部和外部let之间的差异

Module lambda表达式内部和外部let之间的差异,module,scheme,read-eval-print-loop,lexical-scope,guile,Module,Scheme,Read Eval Print Loop,Lexical Scope,Guile,考虑具有以下步骤的模块: (define-module (test test) #:export (proc1 proc2 proc3)) (define proc1 (let ((module (current-module))) (lambda () (format #t "~s\n" module)))) (define proc2 (lambda () (let ((module (current-module))) (fo

考虑具有以下步骤的模块:

(define-module (test test)
  #:export     (proc1 proc2 proc3))

(define proc1
  (let ((module (current-module)))
    (lambda ()
      (format #t "~s\n" module))))

(define proc2
  (lambda ()
    (let ((module (current-module)))
      (format #t "~s\n" module))))

(define (proc3)
  (let ((module (current-module)))
    (format #t "~s\n" module)))
我的印象是,所有这些都是等价的,但事实并非如此

scheme@(guile-user)> (use-modules (test test))
scheme@(guile-user)> (proc1)
#<directory (test test) 562a062152d0>
$1 = #t
scheme@(guile-user)> (proc2)
#<directory (guile-user) 562a05b8bbd0>
$2 = #t
scheme@(guile-user)> (proc3)
#<directory (guile-user) 562a05b8bbd0>
$3 = #t
scheme@(欺骗用户)>(使用模块(测试))
方案@(欺诈用户)>(proc1)
#
$1=#t
方案@(欺诈用户)>(proc2)
#
$2=#t
方案@(欺诈用户)>(proc3)
#
3美元=
只有在
proc1
中,lambda表达式中的
module
符号才绑定到定义过程的模块


有人能解释一下吗?这是否意味着如果要创建闭包,我必须始终使用第一个表单?

只有proc1打印测试模块

proc2和proc3是等效的,它们打印REPL模块

以及在REPL中执行proc1、2、3try(当前模块)。这会让事情变得更清楚


对于proc1(当前模块),在定义过程时执行;对于proc2和proc2(当前模块),在调用过程时执行。

proc1
在定义过程时只计算一次
(当前模块)
,因此,lambda中的
模块
在定义时绑定到该值

proc2
在调用过程之前不会计算
(当前模块)

每次都会对其进行评估。
它相当于
proc3