From: Timothy J. H. <ti...@cs...> - 2004-05-19 19:28:07
|
We've introduced a new module syntax into Jscheme. This is a very lightweight change (mostly just syntax). The new syntax for loading a jscheme file as a module is as follows: (use-module MODULE) (use-module MODULE SPECIFIER) (use-module MODULE SPECIFIER SYMBOLS) (use-module MODULE SPECIFIER SYMBOLS PREFIX) where * MODULE is a either a filename, or a URL, or the name of a compiled Scheme module * SPECIFIER is one of the following: o 'import-procedures o 'import-macros o 'import and it specifies whether to import procedures, macros, or both. The default value is 'import. * SYMBOLS is either the symbol 'all or is a list of symbols. The default value is 'all. In the former case, all symbols defined in the module are imported to the current environment; in the latter case, only those symbols in the list are imported * PREFIX is a string which is prepended to each imported symbol from the module before that value is put into the current environment. The default value is the empty string "". Strings are never prepended to macros as macros are already changing the syntax... Examples: The following are all equivalent: (use-module "elf/basic.scm") (use-module "elf/basic.scm" 'import) (use-module "elf/basic.scm" 'import 'all) (use-module "elf/basic.scm" 'import 'all "") The following examples show how to get more control over what is imported. You can import only procedures, or only macros, or import some subset of the procedure or macros. (use-module "elf/basic.scm" 'import-procedures 'all) (use-module "elf/basic.scm" 'import-procedures '(describe print)) (use-module "elf/basic.scm" 'import-macros 'all) (use-module "elf/basic.scm" 'import-macros '(dotimes)) (use-module "elf/basic.scm" 'import '(describe print dotimes)) Finally, you can add arbitrary prefixes to the symbols that are imported, but prefixes are never applied to the macros. (use-module "elf/basic.scm" 'import-procedures '(describe print) "elf:") (use-module "elf/basic.scm" 'import-procedures '(describe print) "elf-") (use-module "elf/basic.scm" 'import '(describe print dotimes) "elf:") Modules are implemented by creating a new JScheme instance and loading the specified files into that instance. Then copying the specified values to the current environment and binding them to the specified symbols (possibly with prefixes). Each module is cached when it is loaded and that same instance is used for every "use-module". Feedback is welcome. Cheers, ---Tim--- |