\ Named and anonymous modules for Standard Forth. \ Neal Bridges, 2006. \ Version 1.0 Initial release. [undefined] module [if] \ These definitions depend on the Standard Search-Order words: \ definitions get-order set-current set-order wordlist \ and the Search-Order Extension word: \ previous \ Two general-purpose words for working with wordlists: : add-wordlist ( wid -- ) >r get-order r> swap 1+ set-order ; : use-wordlist ( wid -- ) add-wordlist definitions ; \ The module words: : begin-module ( -- ) wordlist use-wordlist ; : public: ( -- ) get-order rot dup set-current rot rot set-order ; : private: ( -- ) definitions ; : end-module ( -- ) previous definitions ; \ Here an anonymous module is used to build the named-module words, thus \ providing a brief example: begin-module \ Begin an anonymous module. \ Initial definitions in a module are private by default, and are only \ visible to definitions within the module. : create-module ( wid -- ) create , does> @ add-wordlist ; public: \ Subsequent definitions will be visible outside the module. wordlist constant modules : module ( "name" -- ) modules set-current wordlist dup create-module use-wordlist ; : expose-module ( "name" -- ) bl word count modules search-wordlist 0= abort" module not found" execute ; end-module [then]