Open raoulvdberge opened 9 years ago
I want to have some sort of module system with explicit exports, I think. But as to how that'll work, I don't know yet.
I was thinking about that too lately, I think it would be ease to build a module system using #18 . a module would just put a record on its stack , eg:
math.firth:
[/sin sin /cos cos /tan tan /pi pi] record.
and we could import it with something like:
/math 'math' import. def.
the import
function might execute the file on a new stack (to prevent the module from messing with the existing stack) and a new scope (to avoid having module that suppose that some other modules are already loaded)
What does record
do?
it's some kind of data structure, but not yet specified : https://github.com/TazeTSchnitzel/Firth/issues/18
We could just do what Node does, yes, and export everything with an object.
On the other hand, I don't like having to look at the bottom of the file to see what's exported. I'd prefer something along these lines:
/foobar [
; ...
] def.
/foobar foobar export.
Or perhaps a combined def-and-export function. Though it's probably best to keep things simple and only have one function that can modify the scope.
the export
function could be nice, with only def.
module would likely export to much stuff without realizing it
Right. If you implicitly export everything, then it's way too easy to accidentally expose something.
People will be lazy and will just use that special def
for everything without thinking about it, so export
would be better indeed.
Will Firth support the including of other files? How will packages (for example, a database package) be imported?
I think this is something to be thought about.