Add some notes on modules in Decoy.
Chris Pressey
1 year, 4 months ago
0 | Notes on Decoy Modules | |
1 | ====================== | |
2 | ||
3 | Unclear how much of this belongs to the Decoy language, vs. | |
4 | how much it belongs to the `decoy` implementation. | |
5 | ||
6 | We'll start with some simple facts, to try to make the | |
7 | situation clearer. | |
8 | ||
9 | ### Evaluating Modules | |
10 | ||
11 | `decoy` is an implementation of Decoy. `decoy` can evaluate modules. | |
12 | ||
13 | Evaluating a module means two things: creating a new environment | |
14 | based on the definitions in the module, and evaluating any | |
15 | bare expressions and displaying the results of them. | |
16 | ||
17 | When you evaluate a module, it needs to have an implementation | |
18 | written in Decoy. (But see below.) | |
19 | ||
20 | When you evaluate a module, it may import other modules. | |
21 | Or you may supply, on the command line, modules to be | |
22 | (implicitly) imported beforehand. | |
23 | ||
24 | Importing a module means evaluating it and providing any | |
25 | new environment it provides to the module that imported it. | |
26 | ||
27 | Either way, when you import a module, it too needs to have | |
28 | an implementation. Usually this implementation is in Decoy. | |
29 | However in the case of "built-in" modules like (presently) | |
30 | `stdenv`, the module implementation will be in Lua. | |
31 | ||
32 | NOTE: This could be the case for other modules too, so that | |
33 | they could access Lua-specific functionality. But that | |
34 | goes against the spirit of Decoy, where functions are pure | |
35 | functions that shouldn't really need access to functionality | |
36 | specific to a specific platform or language. | |
37 | ||
38 | ### Compiling Modules | |
39 | ||
40 | As an implementation of Decoy, `decoy` can also compile modules. | |
41 | ||
42 | Compiling a module means translating it to a module in another | |
43 | programming language. For the moment we will consider primarily | |
44 | JavaScript. But Lua and Scheme would other languages we should | |
45 | consider, since they have very similar operating models. | |
46 | ||
47 | More TBW |