| Although I like most of Arc/Anarki, I think the language is going nowhere without a decent module system. So I've made a simple one, with semantics based on Python's. It's not an exact replica, and it has its flaws; I'm not saying this is the best way, and certainly my implementation could be improved, but at least it's something. The file is in the Anarki git, as lib/module/python.arc. Modules, once obtained, are essentially 'eval equivalents: you give them an expression, and they evaluate it within the module. The most common usage will probably be to get the value of a symbol, (mod 'symbol); for which we can use the ssyntax mod!symbol, just as you would a table. The most important underlying function is 'module-require, which takes a filename and, if it has not been module-required before, creates a new module and loads the file into that module and returns it. Otherwise it returns the module already created. The 'use macro is the primary entry point for using modules. It takes any number of "clauses": (use <clause>...). Clauses currently come in 4 flavors: <name>, eg (use test). This is the simplest form. It module-requires "test.arc" as a module and binds it to 'test. This is "import <name>" in Python. (as <name> <alias>), eg (use (as long/name foo)). This module-requires the file "long/name.arc" as a module and binds it to 'foo. This is "import <name> as <alias>" in Python. (from <name> <syms>...), eg (use (from test myfun mymac)). This requires the file "test.arc" as a module and imports the symbols "myfun" and "mymac" from it into the current module (the toplevel is implicitly a module). This is "from <name> import <syms>, ..." in Python. (all <name>), eg (use (all test)). This loads the file "test.arc" as a module and imports all global symbols in it into the current module. This is "from <name> import *" in Python. This system has several major problems. The biggest is obviously macros. You cannot use macros from a module using the mod!symbol syntax, or the (mod 'symbol) form it translates to. This is a general problem with Arc, IMO: macros are not first-class. This can't be fixed in the general case without changing ac.scm to interpret, rather than translate, arc code. Another problem is that (use (all <name>)) doesn't make the current module "inherit" from <name>, it just binds all symbols currently bound in <name>. So redefinition of a value in <name> won't affect a module that's done (use (all <name>)), nor will definition of a new variable be visible. This is due to the underlying "namespaces" from mzscheme I used to implement the module system. |