+(defun call-with-temporary-module (thunk)
+ "Invoke THUNK in the context of a temporary module, returning its values.
+
+ This is mainly useful for testing things which depend on module variables.
+ This is the functionality underlying `with-temporary-module'."
+ (let ((*module* (make-instance 'module
+ :name "<temp>"
+ :state nil)))
+ (call-with-module-environment
+ (lambda ()
+ (module-import *builtin-module*)
+ (funcall thunk)))))
+