eval.scm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. ;;; R7RS compatibility libraries
  2. ;;; Copyright (C) 2019 Free Software Foundation, Inc.
  3. ;;;
  4. ;;; This library is free software: you can redistribute it and/or modify
  5. ;;; it under the terms of the GNU Lesser General Public License as
  6. ;;; published by the Free Software Foundation, either version 3 of the
  7. ;;; License, or (at your option) any later version.
  8. ;;;
  9. ;;; This library is distributed in the hope that it will be useful, but
  10. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;;; Lesser General Public License for more details.
  13. ;;;
  14. ;;; You should have received a copy of the GNU Lesser General Public
  15. ;;; License along with this program. If not, see
  16. ;;; <http://www.gnu.org/licenses/>.
  17. (define-module (scheme eval)
  18. #:use-module (ice-9 match)
  19. #:export (environment)
  20. #:re-export (eval))
  21. (define (environment . import-specs)
  22. (let ((module (make-module)))
  23. (beautify-user-module! module)
  24. (purify-module! module)
  25. (module-use! module (resolve-interface '(guile) #:select '(import)))
  26. (for-each (lambda (import-spec)
  27. (eval (list 'import import-spec) module))
  28. import-specs)
  29. ;; Remove the "import" import. FIXME: this is pretty hacky stuff :(
  30. (set-module-uses! module (cdr (module-uses module)))
  31. (hash-clear! (module-import-obarray module))
  32. (module-modified module)
  33. module))