More WIP.
[sod] / src / module-impl.lisp
index 753ca0a..5343ad0 100644 (file)
       (when (and truename (not (eq (module-state *module*) t)))
        (remhash truename *module-map*)))))
 
+(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)))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Type definitions.