Closed zaphar closed 5 years ago
Proposed Syntax for a ucg module:
let my_mod = module {
// arguments are specified as a tuple with default values specified for each argument.
hostname="",
port=0,
db="localhost",
db_user="admin",
db_pass="password"
} { // mods do not close over their environment.
// this binding is not visible outside of the module. should be at the time of definition?
// or path should be rewritten to be absolue before instantiation.
import "../../shared.ucg" as shared;
// processing should be delayed till module instantiation.
let base_config = shared.mk_site_config(mod.hostname, mod.port);
let config = base_config{ // processing should also be delayed.
dbs = self.dbs + [
// mod is a special selector inside of a module that refers to the parameters
// of the module.
shared.mk_db(mod.db, mod.db_user, mod.db_pass)
],
};
};
UCG already has a lot of tools for reuse in the form of macros and copy expressions. However macros don't compose very well and Copy Expressions only work at the level of a single tuple. If you need several tuples and macros to work together and don't want to require the user to compose them manually then some way to have a Parameterized Module system is required.