{\rtf1\ansi\ansicpg1252\uc1\deff0
{\fonttbl{\f0\fnil\fprq2 Sans;}
{\f1\fnil\fprq1 Monospace;}
{\f2\fnil\fprq1 Sans Serif;}
}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;}{\stylesheet
{\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0\snext0 Standard;}
{\s1\qc\fi0\f0\fs48\i0\b\cf1\ul0\strike0\snext0 Document Title;}
{\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0\snext0 Head 1;}
{\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0\snext0 Head 2;}
{\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0\snext0 Head 3;}
{\s5\ql\fi0\f0\fs20\i0\b0\cf1\ul0\strike0\snext5 Enumerated List;}
{\s6\ql\fi0\f0\fs20\i0\b0\cf1\ul0\strike0\snext6 Alphabetical List;}
{\s7\ql\fi0\f0\fs20\i0\b0\cf1\ul0\strike0\snext7 Bullet List;}
{\s8\ql\fi0\f1\fs20\i0\b0\cf1\ul0\strike0\snext8 Code;}
{\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0\snext0 Example;}
{\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0\snext0 Transcript;}
{\s11\qc\fi0\f2\fs40\i0\b\ul0\strike0\snext11 Contents Title;}
{\s12\ql\fi0\tqr\tldot\tx9960\f2\fs24\i0\b\ul0\strike0\snext12 Contents Head 1;}
{\s13\li500\fi0\tqr\tldot\tx9960\f2\fs24\i0\b0\ul0\strike0\snext13 Contents Head 3;}
{\s14\li240\fi0\tqr\tldot\tx9960\f2\fs24\i0\b0\ul0\strike0\snext14 Contents Head 2;}
{\s15\qc\fi0\f2\fs40\i0\b\ul0\strike0\snext11 Contents Title;}
{\s16\li240\fi0\tqr\tldot\tx9960\f2\fs24\i0\b0\ul0\strike0\snext14 Contents Head 2;}
{\s17\li500\fi0\tqr\tldot\tx9960\f2\fs24\i0\b0\ul0\strike0\snext13 Contents Head 3;}
{\s18\fi0\tqr\tldot\tx9960\f2\fs24\i0\b\ul0\strike0\snext12 Contents Head 1;}
}{\info {\title The Darwin module system for Lua}{\author James Jennings}{\comment Generated by KWord's RTF Export Filter 549975 }{\creatim\yr2009\mo7\dy24\hr11\min0\sec18}{\revtim\yr2009\mo9\dy4\hr6\min59\sec40}{\printim\yr2009\mo8\dy11\hr13\min32\sec31}}\paperw12245\paperh15817\margl1133\margr1133\margt850\margb850\widowctrl\ftnbj\aenddoc\formshade \fet0\sectd
\pgnstart1
\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\s1\qc\fi0\f0\fs48\i0\b\cf1\ul0\strike0 {The Darwin module system for Lua}
\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\s0\qc\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\'a9 James S. Jennings, 2009}
\par\pard\plain\s0\qc\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Durham, NC, U.S.A.}
\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\par\pard\plain\s0\qc\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 License}}
\par\pard\plain\s0\qc\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Darwin is licensed under the MIT Open Source license reproduced below.}
\par\pard\plain\s0\qc\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:}
\par\pard\plain\s0\qc\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.}
\par\pard\plain\s0\qc\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.}
\par\pard\plain\par\pard\plain\s11\qc\fi0\f2\fs40\i0\b\ul0\strike0 {Table of Contents}
\par\pard\plain\s12\ql\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\b\ul0 1. Introduction\tab 3}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 1.1. Rationale\tab 4}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 1.2. Design goals for Darwin\tab 4}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 1.3. The binding for the name Darwin\tab 5}}
\par\pard\plain\s12\ql\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\b\ul0 2. Design\tab 6}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.1. What is a module?\tab 6}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.2. What is a structure?\tab 6}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.3. Signatures\tab 7}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.4. Module code\tab 8}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.5. Turning Lua code into Darwin modules\tab 9}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.5.1. Lua modules defined with the Lua module function\tab 9}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.5.2. Lua modules defined without the module function\tab 13}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.5.3. Lua modules defined by a file of code that returns a table\tab 14}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.5.4. General Lua code\tab 15}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.6. Special treatment for objects\tab 16}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 2.7. Darwin and Lua's package table\tab 18}}
\par\pard\plain\s12\ql\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\b\ul0 3. Discussion\tab 21}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 3.1. Initializers of package-specific data\tab 21}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 3.2. What makes a good module?\tab 21}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 3.3. Darwin's require, module, and seeall functions\tab 22}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 3.4. Darwin modules and garbage collection\tab 23}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 3.5. Searching for structure declarations\tab 23}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 3.6. Note on starting Darwin\tab 23}}
\par\pard\plain\s12\ql\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\b\ul0 4. Comparison to other module systems\tab 25}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 4.1. Scheme48\tab 25}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 4.2. SML\tab 25}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 4.3. Java\tab 25}}
\par\pard\plain\s12\ql\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\b\ul0 5. Darwin Reference\tab 26}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1. Functions\tab 26}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1.1. structure.declare\tab 27}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1.2. structure.load\tab 29}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1.3. structure.signature\tab 29}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1.4. structure.currentopentable\tab 30}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1.5. structure.preloadtable\tab 30}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1.6. structure.instructure\tab 31}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.1.7. structure.initialize\tab 32}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 5.2. darwin.initialstructures\tab 32}}
\par\pard\plain\s12\ql\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\b\ul0 6. Known bugs, limitations, and planned enhancements\tab 33}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.1. Known bugs\tab 33}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.2. Limitations\tab 33}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.2.1. Code change needed to support MacOS\tab 33}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.2.2. No explicit support for renaming exports\tab 33}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.2.3. No explicit support for importing a subset of bindings\tab 34}}
\par\pard\plain\s14\ql\li240\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.3. Planned enhancements\tab 34}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.3.1. A Meta-Module Protocol?\tab 34}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.3.2. Weak imports\tab 35}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.3.3. Support for importing a subset of bindings\tab 35}}
\par\pard\plain\s13\ql\li500\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\ul0 6.3.4. Functors\tab 36}}
\par\pard\plain\s12\ql\fi0\tqr\tldot\tx9960\f0\fs20\i0\b0\ul0\strike0 {{\f2\fs24\b\ul0 7. Bibliography\tab 38}\page}
\par\pard\plain{\pntext\pard\plain\fs40\f0 1.\tab}{\*\pn\pnlvl1\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs40\pnf0}\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0 {Introduction}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\line The Darwin module system provides a structured module system for Lua.  Darwin is implemented purely in Lua and is compatible with the existing Lua 5.1.x module and package facilities.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Darwin is copyright \'a9 2009 by James S. Jennings, Durham, NC, U.S.A.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 1.1.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Rationale}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Lua is an extraordinarily flexible language.  Conceived originally as a scripting language, it has proven broadly useful in a range of application domains and application sizes.  Lua has a basic module system that provides some namespace control and an (independent) ability to search for modules and files so that the programmer need only supply the name and not the location of the desired code.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {There are two circumstances in which an enhanced module system is needed:}
\par\pard\plain{\pntext\pard\plain\fs20\f0 i.\tab}{\*\pn\pnlvl7\pnlcrm{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When the script writers are users whose scripts should not have the ability to harm the larger system into which Lua is embedded; and}
\par\pard\plain{\pntext\pard\plain\fs20\f0 ii.\tab}{\*\pn\pnlvl7\pnlcrm{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When the amount of Lua code in a project grows beyond some point (perhaps 1k lines) and would benefit not only from partitioning into modules, but also from the composability of modules that derives from a proper, structured module system.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In the first case, one wishes to provide users with libraries of functions with which they can write their scripts (Lua programs).  Suppose two libraries are provided, {\i\ul0 X} and {\i\ul0 Y, }and {\i\ul0 Y }uses functions from {\i\ul0 X.}  The user may be using a combination of functions from {\i\ul0 X }and {\i\ul0 Y, }but in Lua's module system, the user can alter {\i\ul0 X, }which can in turn break the functions implemented in {\i\ul0 Y.  }It may be acceptable (in general) for the user to alter {\i\ul0 X, }if the most harm they can do is to break their own code.  But it is unfortunate if the user can also break {\i\ul0 Y.}  (E.g. a function in {\i\ul0 Y} might be called by the system to process results generated by the user's code.  The user can make the system operations fail!)}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In the second case, one desires not only isolation between modules, but some composability as well.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Isolation is essential in large systems because it eliminates a particularly devilish type of bug that emerges from unexpected interactions between modules.  (Such bugs can appear and disappear depending on the load order of the modules or depending even on the run-time sequence of function calls.)  But isolation is not enough.  In a large system, the dependencies between modules can be difficult to track and maintain.  Having a declarative syntax for module dependencies becomes essential, because it enables static analysis and (by extension) a variety of automated tools.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Sometimes, dependencies can be difficult to resolve, such as when module {\i\ul0 A} requires version 1 of module {\i\ul0 util}{\i\ul0  }and module {\i\ul0 B }only works with version 2 of {\i\ul0 util}{\i\ul0 .}  The notion of "composition" addresses this problem.  When modules are composable, we can construct {\i\ul0 A} using version 1 of {\i\ul0 util}{\i\ul0 , }and construct {\i\ul0 B} using version 2 of {\i\ul0 util}{\i\ul0 .}  The resulting system can contain both {\i\ul0 A }and {\i\ul0 B}.  We would say that the system is composed of modules {\i\ul0 A }and {\i\ul0 B, }where {\i\ul0 A }and {\i\ul0 B }are, in turn, composed of other modules.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 1.2.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Design goals for Darwin}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Isolation:} Module code should be sufficiently isolated from code that uses the module such that no user of a module can interfere with another user of the same module.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Namespace control:} When a module is used, no bindings should be exposed other than those in the designed interface to the module.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Declarative dependency representation: }Dependencies between modules should be declared in a way that enables static analysis whether by automated tools or simply by visual inspection. }
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Interface specification:} The interface to a module should be able to be specified separately from the code that implements it, in order to allow the substitution of alternate implementations.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Simplicity:} The module system should be as simple as possible in order to promote adoption, e.g. by providing precise definitions of familiar concepts (like "module") and avoiding the introduction of many new concepts.  Most importantly, it should be possible to write Lua (and C) code without thinking about the module system, and then to use that code later in a module.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Backwards compatibility:} The module system should effortlessly co-exist with the existing Lua 5.1.4 module features (where Lua modules have the same features and limitations as today), and further to provide ways to reuse existing Lua module code in the Darwin system in order to obtain additional benefits (e.g. isolation and namespace control).}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Separate compilation:} The design of the module system should accommodate the separate compilation of modules and also the dynamic loading of both Lua and C modules that is provided today in Lua 5.1.4.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 1.3.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {The binding for the name Darwin}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The name Darwin{\i\ul0  }is not an allusion to Charles Darwin, nor to the process of natural selection he identified. It is also not a reference to any part of any Apple Operating System. Darwin is the name of my dog.}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain{\pntext\pard\plain\fs40\f0 2.\tab}{\*\pn\pnlvl1\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs40\pnf0}\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0 {Design}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The rest of this paper describes the concepts and artifacts of the Darwin module system for Lua. References to {\i\ul0 module }mean {\i\ul0 Darwin module; }references to {\i\ul0 Lua module} refer to the modules of Lua 5.1.4. Generally, where there is overlap in terminology between Lua 5.1.4 and Darwin 1.0.0, the reader should assume the Darwin binding for all unqualified terms. }
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 2.1.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {What is a module?}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A {\i\ul0 module} is a collection of bindings, where a {\i\ul0 binding} maps a name to a location in the store.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A {\i\ul0 module system }(like Darwin) specifies how modules are created, manipulated, and used. By far the most common use of a module is to {\i\ul0 open }it, i.e. to make its bindings {\i\ul0 accessible }in the current environment.  Sometimes called {\i\ul0 importing the bindings of a module, }the process of opening a module involves a sort of merging of the module environment into the current environment (where the {\i\ul0 open }is occurring).}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 2.2.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {What is a structure?}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In Darwin, we use the term {\i\ul0 structure} instead of module, partly due to the influence of SML and Scheme48, and partly because Lua already uses the term 'module' and has a function of the same name.  A {\i\ul0 structure }in Darwin is a run-time object that encapsulates everything about a module:}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {the code that implements the module (or references to files containing that code);}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {other modules opened by this module;}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {the signature of the module;}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {and, any special treatment that might be needed for objects created by the module code.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {To {\i\ul0 declare} a structure, you use a data structure that specifies any of these items that pertain to your module.  Tables are the data structure in Lua, so a structure declaration is a Lua table.  Let's look at a simple example before we discuss the occasional need for "special treatment" stated in the list above.  We will come to that topic before the end of Section 2.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The following example declares a "list module", in other words, a module that defines a list data type.  In Darwin terminology, this example declares the {\i\ul0 list }structure:}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare \{ name="list"; }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   location="."; }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   open=\{"_G"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   objects=\{"null"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   files="list.lua";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The declaration itself is the table with the slots {\i\ul0 name, location, }etc.  As written, this example calls the function {\i\ul0 structure.declare }on that table.  Later, we will see how structures are loaded and used.  The example above shows only how a structure is declared.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The code for the example structure is in the file "list.lua".  (Note: The files clause will accept a single file name or a table of file names.) The functions {\i\ul0 structure.}{\i\ul0 getpath}{\i\ul0  }and {\i\ul0 structure.}{\i\ul0 setpath}{\i\ul0  }can be used to read and write the search path for file names that appear in a Darwin structure declaration.  The example declaration states that the code implementing the {\i\ul0 list }structure requires the functions in the base library {\i\ul0 _G.}  We will explain the location and objects clauses later.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The actual run-time object created when a structure is declared contains, additionally, the module environment (the actual collection of bindings) and a bit of state.  The module environment is empty until the module is loaded, and the state reflects whether or not the module is loaded.  Before a module can be {\i\ul0 opened, }it must be {\i\ul0 loaded, }which means that the code that implements the module must be loaded and (if necessary) compiled, and then executed.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 2.3.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Signatures}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {One of our design goals is to allow the separate specification of a module's implementation from its interface.  A module's {\i\ul0 interface }is the set of bindings that become accessible when the module is opened.  We say that a module {\i\ul0 exports }these bindings.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Inspired by Scheme48's module system (and, therefore, by SML modules), each Darwin module has a {\i\ul0 signature, }which is a list of the names exported by a Darwin module.  Each name is a string.  No matter how many global variable bindings are created by the Lua code that implements a module, only the subset of those bindings specified by the signature will be accessible by users of the module.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Recall the first example in this document, which declared the {\i\ul0 list }structure.  The file "list.lua" contains 27 global definitions, and all 27 are available whenever the {\i\ul0 list }structure is opened.  But suppose I want to expose only a few of those 27 definitions, e.g. just the ones that are needed to support Scheme's {\i\ul0 pair }datatype.  I can declare a structure that provides only those functions:}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare \{ name="pair"; }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   signature=\{"cons", "car", "cdr", "isnull", "null"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   open=\{"_G"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   objects=\{"null"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab   files="list.lua";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The {\i\ul0 signature }clause lets me list exactly the definitions that I want exposed when the {\i\ul0 pair }structure is opened.  Below is a sample transcript showing an interactive Lua session (with Darwin loaded), where the {\i\ul0 pair }structure is declared, opened, and used.  Note that in normal use, the {\i\ul0 pair }structure declaration would be in a file, and the {\i\ul0 pair }structure would likely be opened by being named in the {\i\ul0 open }clause of another declaration.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Darwin 1.0.2 Copyright (c) 2009 James S. Jennings}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Current package is 'user'.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare \{ name="pair"; }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab \tab  signature=\{"cons", "car", "cdr", "isnull", "null"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab \tab  open=\{"_G"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab \tab  objects=\{"null"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab \tab  files="list.lua";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab \tab \tab \tab \}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "pair"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =pair.null}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\{\}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =pair.cons("a", pair.cons("b", pair.null))}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\{a, b\}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =pair.isnull(pair.null)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {true}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The signature concept provides 3 key benefits:}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A declared signature can be inspected as part of a static analysis.  (On a related note, a signature answers the user's question "What is exported?" more reliably than by reading the code, and without having to load the module.)}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A family of modules may be built by using different signatures to expose the same implementation in different ways.  A common use case occurs when the module writer wants to provide both a "standard" interface to users of the module and a "debugging" (or "internals") interface which exposes the inner workings to aid the development of programs that use the module.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {By separating the signature from the implementation, it is possible to substitute an alternate implementation of the module without changing any of the code that uses the module.  In practice, this is rarely achieved in any programming system, but it's a nice idea.  Actually, it does work in practice for a useful class of problems: the implementation of (very) well-specified data structures.   }
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Like SML, and unlike Scheme48, Darwin does not force the programmer to supply a list of exported bindings.  If a list is provided in the module declaration, it is used.  Otherwise, the signature is automatically constructed (when the module is loaded) and is essentially the list of global bindings created by the module code.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {More precisely, when Darwin automatically constructs a module signature, it starts with a list of all the global bindings in the module environment (more on that environment later).  All names that match bindings imported from other modules are filtered out.  Lastly, all global tables are assumed to be "substructures" that contain more bindings, and their contents are recursively added to the module's signature.  The rationale for and implications of this approach are discussed in the section "Special treatment for objects" below.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 2.4.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Module code}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The code that implements a Darwin module can come from many places.  In nearly all cases, Darwin modules may be built out of code that was not written with modules in mind \emdash  neither Lua modules or Darwin modules.  We shall see, later, however, that both ordinary Lua code and existing Lua modules can easily be turned into Darwin modules.  Darwin's structure declaration facility supports:}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {code supplied as strings in the structure declaration;}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {code loaded from files;}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {and, bindings that have already been created by any means that Lua supports for finding, loading, and running code.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The ability to put module code into strings given in a structure declaration is primarily meant for exposition, but it does have a practical use as well.  If almost all of the code you need is in a file, you can specify the file name in the structure declaration and then provide additional code as a literal string.  The additional code might establish a preferred set of default values, or it might define and insert hook functions to customize the behavior of the code stored in the file.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We expect that, most commonly, code will be loaded from files.  The semantics of loading code from a file in Darwin match those of Lua's {\i\ul0 dofile} \emdash  in fact, {\i\ul0 dofile}{\i\ul0  }is used in the implementation of Darwin.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The third way that a module can be created from existing Lua code is to use the {\i\ul0 environment }clause in a structure declaration.  The environment clause accepts either a table or a string.  If a table value is supplied, then that table becomes the module environment.  This is how the standard Lua libraries are exposed by Darwin as modules:  Their tables (e.g. math, string, debug, ...) are supplied in an environment{\i\ul0  }clause in a structure declaration.  Note that the {\i\ul0 open }clause is irrelevant in this scenario, because the structure declaration contains actual bindings, not code requiring an environment in which it must be loaded and executed.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {If, on the other hand, you supply a string value in the environment clause instead of a table value, Darwin will treat the string as code that produces the module environment.  The code will be run in a sandbox, and it must produce a table as the first returned value.  That table becomes the module environment; any other returned value are discarded.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The sandbox is the environment in which Darwin loads and executes the code string in the environment clause.  Once the resulting table value is obtained, the sandbox is discarded.  (Of course, the code in the string may well have created closures over objects in the sandbox, or even of the entire sandbox!)}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The sandbox is created by opening all of the structures declared in the {\i\ul0 open }clause, and then loading all the files specified in {\i\ul0 files, }and then executing all of the other code strings from the structure declaration in order.  Finally, the code string given in the environment clause is processed to produce the final environment table.  The next section explains how to re-use existing Lua code as the content for Darwin modules.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 2.5.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Turning Lua code into Darwin modules}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Perhaps the most important attribute of Darwin is that Darwin modules can be easily assembled using existing Lua (and C) code.  Lua modules are commonly used today, and it is easy to turn Lua modules into Darwin modules, even though Lua modules may be constructed in a variety of ways.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 2.5.1.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {Lua modules defined with the Lua module function}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The Lua module function creates a table and sets the (default) function environment for the loader function to be that table.  The loader is the function that is processing the code, e.g. {\i\ul0 dofile}{\i\ul0 .  }All of the bindings created by the loader function (after the module function is called) will be created in the module table, and function values will have that table as their function environment.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The {\i\ul0 package.}{\i\ul0 seeall}{\i\ul0  }function in Lua is needed because the global environment is not accessible from the table created by the module function.  The optional arguments to Lua's module function are functions, and {\i\ul0 package.}{\i\ul0 seeall}{\i\ul0  }is a function which creates a metatable for its table argument where {\i\ul0 __index=_G, }so that the global environment becomes accessible.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {It is easy to build a Darwin module which reuses a Lua module without changes.  When a Lua module creates a table containing the desired module bindings, you can assign that table to be the environment of a Darwin module with the {\i\ul0 environment }clause.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare \{ name="lanes";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    open=\{"_G", "package", "table", "string"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    environment=[[ require("lanes"); return lanes ]];}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                  \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The example above is based on a real package, Lua Lanes 2.0.3 ({\field{\*\fldinst HYPERLINK http://luaforge.net/projects/lanes}{\fldrslt {\ul\cf2http://luaforge.net/projects/lanes}}}).  The code that implements Lanes is written in C and Lua.  The Lua code uses functions from three of the standard Lua libraries: the basic functions in {\i\ul0 _G}, plus functions from the {\i\ul0 table} and {\i\ul0 string} libraries. The declaration above opens {\i\ul0 package }as well, because Lua defines the package{\i\ul0  }library as two functions, {\i\ul0 require }and {\i\ul0 module, }together with the {\i\ul0 package }table.  The Lanes code does not need the package{\i\ul0  }library, but the code inside the structure declaration does \emdash  it calls {\i\ul0 require.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Recall that the value supplied in the environment clause must be either a table or code (a string value) that returns a table.  Before Darwin, we would write {\i\ul0 require("lanes"), }so that is what goes into the environment clause.  However, the code must return a table, and we know that the call to {\i\ul0 require }will produce the table {\i\ul0 lanes. } Therefore, we end the environment code string with {\i\ul0 return lanes.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {After the declaration in the example above, we can use the lanes structure in several different ways.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 1.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When we declare another Darwin module that uses Lanes, we include "lanes" in the open clause of that declaration.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 2.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When we load Lua code that calls {\i\ul0 require("lanes"), }the lanes structure will be opened automatically, because Darwin inserts entries into {\i\ul0 package.}{\i\ul0 preload} for each declared structure, so that the declared structure will be shared by all structures that open it.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 3.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In an interactive Lua session, we can issue either {\i\ul0 structure.open "lanes"}, or {\i\ul0 require "lanes" }at the prompt.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Notice that there is no longer any need for {\i\ul0 package.}{\i\ul0 seeall}{\i\ul0 .}  Lua's {\i\ul0 package.}{\i\ul0 seeall}{\i\ul0  }provided the module code with access to {\i\ul0 _G }with no way to guarantee that the bindings in {\i\ul0 _G }would be the ones that were expected by the author of Lanes. Suppose we redefine some of the names in {\i\ul0 _G }before loading the Lua lanes module (as opposed to the Darwin lanes module, declared in the example above).  We can easily break Lanes.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {With the Darwin module system, Lanes is much more likely to work as expected because the Lanes code receives a pristine set of bindings from the _G structure as a result of {\i\ul0 opening }"_G".}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We can also write more "secure" code with Darwin.  Perhaps it is better to say that we can better control the set of bindings available to module code using Darwin.  For example, suppose that the Lanes code calls {\i\ul0 os}{\i\ul0 .execute }(although it does not) and you want Lanes to use your own customized version of {\i\ul0 os}{\i\ul0 .execute, }perhaps because your version implements a "white list" or some other form of validation on the function's argument.  Darwin can ensure that Lanes has access only to your version of {\i\ul0 os}{\i\ul0 .execute }and not the Lua standard version.  Let's look at two reasonable ways to do this.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We will use a very simple module for our example.  We will define the structure environment using a code string without referring to any files, just to keep the example small.  First, let's declare a structure that exports a function, f, which uses {\i\ul0 os}{\i\ul0 .execute.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \{ name="test";}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      open=\{"_G", "os"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      environment=}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {        [[ function f() os.execute("date") end; return \{f=f\} ]]}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "test"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> test.f()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Sun Jul 26 08:32:08 EDT 2009}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In our simple example, the code for the entire module is given in a literal string.  But in general, the module code is more likely to be contained in one or more files.  We can ensure that our own version of {\i\ul0 os}{\i\ul0 .execute }will be called by the functions in those files by installing our own {\i\ul0 os}{\i\ul0 .execute }into the environment.  One approach is to leverage the ability to insert code as strings into a structure declaration, knowing they will be executed before the environment clause is processed.  The change from the previous example is highlighted.}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \{ name="test";}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      open=\{"_G", "os"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      {\cf2\ul0 pre}{\cf2\ul0 =[[ local exec=}{\cf2\ul0 os}{\cf2\ul0 .execute;}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0              }{\cf2\ul0 os}{\cf2\ul0 .execute=function(...)}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0                           print("Running }{\cf2\ul0 os}{\cf2\ul0 .execute...");}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0                           exec(...);}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0                           print("done.");}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0                         end}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0           ]];}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      environment=}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {        [[ function f() os.execute("date") end; return \{f=f\} ]];}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Warning: replacing existing structure test}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.close "test"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "test"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> test.f()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Running os.execute...}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Sun Jul 26 08:26:49 EDT 2009}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {done.}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {>}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The code we added used the "pre" declaration clause.  This clause is named "pre" because Darwin processes it before the "files" clause.  There is a symmetric clause called "post" that is evaluated after "files".  The last clause processed is "environment".}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A good convention is to put the environment clause last, as shown, in order to emphasize that Darwin processes this clause last.  The actual order of the declaration elements is irrelevant, since the declaration itself is a table with string keys.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Let's return to our example in which we want to provide our own "os.execute" function.  Another approach, perhaps a better one than the previous example, is to define our own os module which contains our own versions of the Lua os library functions.  Then we can use our own os module instead of the Lua one wherever we need it.  And, changes to our module can be made in one place, where our module is defined, instead of in each structure declaration that needs our custom os functions.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \{ name="my_os";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    open=\{"_G", "os"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    environment=}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      [[ local exec = os.execute;}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {         os.execute=function(...)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      print("Running os.execute...");}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      exec(...);}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      print("done.");}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    end;}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {         return os}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      ]]}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {This example (above) is not quite right, however.  When a Darwin module is opened, by default the module bindings appear in a table named after the module.  In the example above, opening "my_os" will create a table {\i\ul0 my_}{\i\ul0 os}{\i\ul0  }with entries such as {\i\ul0 my_}{\i\ul0 os}{\i\ul0 .date, my_}{\i\ul0 os}{\i\ul0 .execute, }etc.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We want the bindings of "my_os" ({\i\ul0 date, execute, ...}) to appear in a table called "os" so that we can use "my_os" as a replacement for "os".  Darwin's structure declaration facility provides a {\i\ul0 location }keyword with which you can specify where the bindings should appear.  The location clause accepts a string value, which is the table name.  The name may contain the dot "." character, in which case it specifies a nested table, e.g. "a.b".  Or, the name may be the dot character by itself, which has the special meaning of "at the top level".}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Here is the declaration we want.  The additional line is highlighted.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \{ name="my_os";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    {\cf2\ul0 location="}{\cf2\ul0 os}{\cf2\ul0 ";}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    open=\{"_G", "os"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    environment=}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      [[ local exec = os.execute;}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {         os.execute=function(...)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      print("Running os.execute...");}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      exec(...);}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      print("done.");}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    end;}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {         return os}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      ]]}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Now we can go back to our interactive Lua session and try out a declaration for a module that was written to use the Lua{\i\ul0  }{\i\ul0 os} module, but which we will force to use our custom{\i\ul0  my_OS} package.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \{ name="test";}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      open=\{"_G", "my_os"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      environment=}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {        [[ function f() os.execute("date") end; return \{f=f\} ]];}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Warning: replacing existing structure test}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.close "test"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "test"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> test.f()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Running os.execute...}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Sun Jul 26 12:43:39 EDT 2009}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {done.}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {>}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Notice that Darwin warns that we are redefining the structure {\i\ul0 test, }which was defined by our first attempt in a prior example.  When we see that warning, we should make sure that we close the current structure {\i\ul0 test, }if it was already open.  Otherwise, {\i\ul0 structure.open "test" }will return immediately because "test" (using the prior declaration) was already open.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 2.5.2.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {Lua modules defined without the module function}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Using the Lua module function is one way to create a named table of bindings.  Another technique is to write a file containing just one global variable assignment: one that assigns the module name to a table of bindings.  To turn such a Lua module into a Darwin module, exactly the same approach is used as in the previous section (where the Lua module function was used).}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {For example, consider a file containing this code:}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 FILE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {-- file "mtest.lua"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local x=1}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local function get_function() return(x) end}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local function set_function(v) x=v end}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {mtest = \{get=get_function, set=set_function\}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When this code is loaded into Lua, e.g. with{\i\ul0  }{\i\ul0 dofile}{\i\ul0 ("}{\i\ul0 mtest}{\i\ul0 .}{\i\ul0 lua}{\i\ul0 ")} or{\i\ul0  require("}{\i\ul0 mtest}{\i\ul0 "),} the net effect is the creation of the table{\i\ul0  }{\i\ul0 mtes}t at top level, with the two module functions accessible as{\i\ul0  }{\i\ul0 mtest}{\i\ul0 .get} and{\i\ul0  }{\i\ul0 mtest}{\i\ul0 .set.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {For example:}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> require "mtest"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {1}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest.set(99)}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {99}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {>{\ul0 > structure.declare}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0     \{ name="test";}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0       open=\{"_G", "my_}{\ul0 os}{\ul0 "\};}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0       environment=}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0         [[ function f() }{\ul0 os}{\ul0 .execute("date") end; return \{f=f\} ]];}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0     \}}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 Warning: replacing existing structure test}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 > structure.close "test"}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 > structure.open "test"}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 > test.f()}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 Running }{\ul0 os}{\ul0 .execute...}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 Sun Jul 26 12:43:39 EDT 2009}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 done.}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 >}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We can use exactly the same approach taken in the previous section to create a Darwin module.  We know that after{\i\ul0  require "}{\i\ul0 mtest}{\i\ul0 ",} we will have a table called{\i\ul0  }{\i\ul0 mtest} which contains the bindings we want in our Darwin module.  Here's how the structure can be declared and tested:}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \{ name="mtest";}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      open=\{"package"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      environment=[[ require("mtest"); return mtest ]]}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "mtest"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {1}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest.set(2000)}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {2000}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 2.5.3.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {Lua modules defined by a file of code that returns a table}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Some people write Lua modules by constructing a file of code that returns a table containing the module bindings.  To turn such a module into a Darwin module, we use a variation on the technique shown in the prior section.  In this case, we know that {\i\ul0 require }{\i\ul0 modname}{\i\ul0  }(or, alternatively, {\i\ul0 dofile}{\i\ul0  }{\i\ul0 filename}) returns the table we are looking for.  So, once again we use the environment clause.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 FILE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {-- file "mtest2.lua"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local M=\{\}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local x=1}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {function M.get() return(x) end}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {function M.set(v) x=v end}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {return M}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> m = require "mtest2"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =m.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {1}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =m.set(1010)}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =m.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {1010}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {>}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Given the code in "mtest2.lua" and how it is meant to be used, here is how to turn the Lua module {\i\ul0 mtest}{\i\ul0 2 }into a Darwin module:}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \{ name="mtest2";}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      open=\{"package"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {      environment=[[ return require("mtest2") ]]}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    \}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "mtest2"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest2.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {1}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest2.set(5)}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =mtest2.get()}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {5}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 2.5.4.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {General Lua code}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Sometimes, developers use the Lua {\i\ul0 require }function to load files of arbitrary code that are unrelated to modules.  The benefit of using {\i\ul0 require }instead of {\i\ul0 dofile}{\i\ul0  }is that {\i\ul0 require }searches for the Lua file, and once loaded, will not load the file again.  Both {\i\ul0 require }and {\i\ul0 dofile}{\i\ul0  }can be used separately or together in order to load arbitrary units of code and (typically), thereby creating a set of bindings to useful functions.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We may wish to turn an arbitrary collection of code (such as might be loaded today using a set of {\i\ul0 require }and {\i\ul0 dofile}{\i\ul0  }calls) into a Darwin a module.  Suppose we have a project whose code starts with:}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {require "lanes"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {dofile "mtest.lua"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {set_debug_mode = function() DEBUG=true; end}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We could package up this preamble into a module that, when opened, would have the same effect.  The declaration would look like this:}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \{ name="projectx";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    location=".";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    open=\{"_G", "package"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    pre = [[ {\cf2\ul0 require "lanes"}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0              }{\cf2\ul0 dofile}{\cf2\ul0  "}{\cf2\ul0 mtest}{\cf2\ul0 .}{\cf2\ul0 lua}{\cf2\ul0 "}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\cf2\ul0              set_debug_mode = function() DEBUG=true; end}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {          ]]}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Here we use the special value "." in the location clause to tell Darwin to export the bindings of {\i\ul0 projectx}{\i\ul0  }into the top level (i.e. global) environment.  Notice that we were able to copy the 3-line preamble code (highlighted) without modification into the body of the declaration of {\i\ul0 projectx}{\i\ul0 .}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Opening {\i\ul0 projectx}{\i\ul0  }makes these bindings available in the global environment:}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 lanes }(a table containing {\i\ul0 lanes.gen, lanes.}{\i\ul0 linda}{\i\ul0 , }etc.)}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 mtest}{\i\ul0  }(a table containing {\i\ul0 mtest}{\i\ul0 .get }and {\i\ul0 mtest}{\i\ul0 .set})}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 set_debug_mode }(a function defined in the declaration of {\i\ul0 projectx})}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Note that there is good value obtained for the small effort of creating the projectx module and using it when developing (and later shipping) Project X:  We can do whatever we want to _G in the working environment without affecting the functioning of {\i\ul0 lanes} or {\i\ul0 mtest}.  Due to Darwin's isolation of the working {\i\ul0 _G }from the {\i\ul0 _G }in which {\i\ul0 lanes} and {\i\ul0 mtest} were loaded, we will get consistent behavior of lanes and mtest code every time, from development through test and on to production use.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 2.6.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Special treatment for objects}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Tables are more than just {\i\ul0 the }data structure{\i\ul0  }in Lua \emdash  they are also the data structure used for environments!  It is wonderful that function environments are first-class objects in Lua and that they are implemented using a simple data structure.  Many benefits derive from these design decisions, including the ability to modify Lua's behavior, e.g. with {\i\ul0 strict.}{\i\ul0 lua}{\i\ul0 , }which signals an error when an uninitialized global is used.  Also, the implementation of Lua's module and package.seeall functions are models of simplicity.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {However, while a rose is a rose is a rose, a table is not always an environment.  Suppose a module M exports a name Foo{\i\ul0  }which denotes a table value.  Foo{\i\ul0  }may be an environment within M, in other words, a table containing a set of bindings.  In common Lua fashion, the module writer may have grouped his functions into tables within M, using M.Foo to hold the bar, bat, and baz functions.  The module writer expects the module user to access these bindings by writing M.Foo.bar, etc.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Opening M makes accessible the bindings "M.foo.bar", etc.  What Darwin actually provides to the module user is a {\i\ul0 private copy }of these bindings, in order to isolate the module users from one another.  So far, so good.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {But what if the table Foo is not a collection of bindings, but is instead an "object" with three initial slots defined (bar, bat, and baz)?  Because it is an object, Foo probably has a metatable that shapes its behavior.  When Darwin exports bindings, it ignores metatables.  That is, Darwin creates plain tables in the user environment to hold the bindings of modules opened by the user.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {So, while the the developer may intend Foo to be an instance of an object, Darwin has no way to know whether Foo is an object or a collection of bindings (another environment) within M.  This scenario cannot be detected programmatically.  The presence of a metatable is a good clue, but an object need not have a metatable.  How can Darwin know the intended use of Foo?}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When the need arises to export a binding to an object, the module writer informs Darwin that this is the case by using the {\i\ul0 objects }clause of the structure declaration.  For each object listed, the user of the module receives a binding to the object, not to a new table with equivalent contents.  The user sees a binding to the object itself, metatable and all.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 FILE EXAMPLE }}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {-- file "memo.lua"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local function compute(string)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {   -- An expensive calculation would go here,}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {   -- but we will just calculate string length instead}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {   return #string}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {end}
\par\pard\plain\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local mt = }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \{ __index = function(self, key)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                local result = compute(key)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                rawset(self, key, result)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                return result}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {              end}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {results = setmetatable(\{\}, mt)}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The file in the example above defines an object called {\i\ul0 results, }which is a table that memoizes the {\i\ul0 compute }calculation on the keys of the table.  The user of the module may request {\i\ul0 results[k] }for any {\i\ul0 k, }and the results object will either return the already-known value or compute the value and store it for future requests.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Our first attempt at a structure declaration will fail because Darwin will treat {\i\ul0 results }as a collection of bindings to export.  (Although the table happens to be empty.)}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE} }
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare \{ name="memo";}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      open=\{"_G"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      files="memo.lua"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    \}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "memo"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =memo.results["Hello"]}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {nil}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =getmetatable(memo.results)}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {nil}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We should have received 5 as the value of {\i\ul0 memo.results["Hello"], }because the compute function returns the length of its argument.  We need to tell Darwin to treat {\i\ul0 results }as an object.  This is the right declaration:}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.declare \{ name="memo";}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      open=\{"_G"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      objects=\{"results"\};}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                      files="memo.lua"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    \}}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "memo"}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =memo.results["Hello"]}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {5}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =rawget(memo.results, "Goodbye")}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {nil}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =memo.results["Goodbye"]}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {7}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =rawget(memo.results, "Goodbye")}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {7}
\par\pard\plain\s10\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {>}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We can see in the transcript above that using {\i\ul0 objects }produced the right effect.  Clearly, {\i\ul0 results }has its metatable intact, because the object functions as we expect it to function (as demonstrated by the use of {\i\ul0 rawget}{\i\ul0  }to inspect what is happening inside the table).}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 2.7.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Darwin and Lua's package table}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {By default, Darwin is completely unrelated to Lua's package table.  When you open a structure, it does not appear in {\i\ul0 package.loaded.}  Conversely, when you {\i\ul0 require }a module, the require function will not be aware of structures that might be declared.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {However, it is often desirable to have exactly the opposite behavior, i.e. for open structures to appear in {\i\ul0 package.loaded }and for the {\i\ul0 require }function to open a structure if there is one declared with the right name.  Darwin provides an easy way to do this.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When you open the {\i\ul0 package }structure, you get bindings for {\i\ul0 require, structure, }and{\i\ul0  package.  }Darwin maintains a table of all declared structure names in a {\i\ul0 preload}{\i\ul0  table}, in which each key is a structure name, and all the values are the function {\i\ul0 structure.open. } If you set the metatable index of {\i\ul0 package.}{\i\ul0 preload}{\i\ul0  }to be Darwin's preload table, then {\i\ul0 require(}{\i\ul0 modname}{\i\ul0 ) }will exhibit the desired behavior:}
\par\pard\plain{\pntext\pard\plain\fs20\f0 1.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {If {\i\ul0 package.loaded.}{\i\ul0 modname}{\i\ul0  }then return this value}
\par\pard\plain{\pntext\pard\plain\fs20\f0 2.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {If {\i\ul0 package.}{\i\ul0 preload}{\i\ul0 .}{\i\ul0 modname}{\i\ul0  }then run this function, i.e. open the structure {\i\ul0 modname}{\i\ul0 .}}
\par\pard\plain{\pntext\pard\plain\fs20\f0 3.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Else start iterating over the functions in {\i\ul0 package.loaders.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The Darwin function {\i\ul0 structure.}{\i\ul0 preloadtable} returns the global preload table.  The function takes no arguments.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {But we also want open structures to appear in {\i\ul0 package.loaded, }so that {\i\ul0 require(}{\i\ul0 modname}{\i\ul0 ) }will simply return {\i\ul0 package.loaded.}{\i\ul0 modname}{\i\ul0  }if {\i\ul0 modname}{\i\ul0  }is an open structure.  Darwin provides access to the table of open packages for the current package, and the {\i\ul0 open package table }has the same format as {\i\ul0 package.loaded.}  If you set the metatable index of {\i\ul0 package.loaded }to be the Darwin {\i\ul0 open package table }for the current package, then all of the open packages will appear in {\i\ul0 package.loaded.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The Darwin function {\i\ul0 structure.}{\i\ul0 currentopentable} returns the table of open packages for the current package.  The function takes no arguments.  Do not modify the table obtained through this function.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {This is how Darwin might define the {\i\ul0 user package }in order to enable {\i\ul0 require }to open structures and to have all open structures appear in {\i\ul0 package.loaded.}}
\par\pard\plain\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f0\fs20\i0\b\cf1\ul0\strike0 {CODE EXAMPLE}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \{ name="user"; }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    open=\{"_G", "structure", "package"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    pre = [[ package.initialize();}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {             setmetatable(package.preload,}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                          \{__index=structure.preloadtable()\})}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {             setmetatable(package.loaded,}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                          \{__index=structure.currentopentable()\})}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {          ]]}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Notice the call to {\i\ul0 package.initialize }in the example above.  This statement is necessary due to a design decision to keep Darwin as uniform as possible.  In brief, each user of the {\i\ul0 package }structure needs its own private copy of the {\i\ul0 package }table, because each Darwin package may have a different set of open packages from all other packages.  Within a module system like Darwin, there is only one instance of each structure, so if we had written {\i\ul0 require }to be closed over a package table, then every package that uses {\i\ul0 require }would share that table.  (This is, in fact, how plain Lua works.)}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In order for each package to have its own {\i\ul0 package }table, the {\i\ul0 require }function looks up the package table in the current environment whenever it needs it, instead of referring to a local variable (an "upvalue").  But the local package table must be initialized before it can be used; hence the need for {\i\ul0 package.initialize.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {For convenience, the Darwin versions of the {\i\ul0 require }and {\i\ul0 module }functions automatically call package.initialize if it has not already been called.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Important note:}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The technique of linking {\i\ul0 package.}{\i\ul0 preload}{\i\ul0  }and {\i\ul0 package.loaders }to Darwin is intended for use {\ul0 when loading code into the user package, such as }during an interactive Lua session.  Darwin modules should {\b\ul0 not }use the Lua require function to load Darwin structures.  Instead, the structures needed by a module should be declared in the open clause of the structure declaration.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A correct example is:}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 structure.declare}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0   \{ name="geometry"; }}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0     open=\{"_G", "matrix", "class"\};}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0     files=\{"geometry-objects.}{\ul0 lua}{\ul0 ", "dim2.}{\ul0 lua}{\ul0 ", "dim3.}{\ul0 lua}{\ul0 "\}}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\ul0   \}}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The files listed in this example may call the require function with any of the open structures as an argument ("_G", "matrix", or "class").   The default {\i\ul0 package.}{\i\ul0 preload} table is empty, and the default {\i\ul0 package.loaded} table contains entries for all of the structures that Darwin opened, i.e. all of structures listed in the open clause.  As a result, suppose "dim2.lua" included the statement: {\i\ul0 require "matrix".}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The call to {\i\ul0 require} will simply return {\i\ul0 package.loaded.matrix}, because the matrix structure was already loaded by Darwin and opened in the geometry environment.  Contrast this scenario with the following {\b\ul0 incorrect} example.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 INCORRECT CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \{ name="geometry"; }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    open=\{"_G"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    files=\{"geometry-objects.lua", "dim2.lua", "dim3.lua"\}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 Note that the declaration does }{\b\ul0 not }{\ul0 open the matrix or class structures.  Of itself, this is not an error.  However, let's assume that both of these structures have been declared, which was also the case in the prior (correct) example.  Suppose one of the geometry files, such as "dim2.}{\ul0 lua}{\ul0 " included the statement: }{\i\ul0 require "matrix".}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 The matrix structure is not listed in the open clause of the geometry structure declaration, so there will be no }{\i\ul0 package.loaded.matrix }{\ul0 entry.  Recalling that the default }{\i\ul0 package.}{\i\ul0 preload}{\ul0  table is empty, the require function will start looking for a loader for "matrix" using the package.loaders table.  If it succeeds, the Lua module (or non-module) called "matrix" will be loaded.  The geometry package may work correctly, but it will }{\b\ul0 not}{\ul0  be using the declared matrix structure.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 Of course, it is possible to insert entries into }{\i\ul0 package.}{\i\ul0 preload}{\ul0  such that requiring "matrix" will cause the matrix structure to be opened.  However, this is not the intended way to use Darwin.  The intended usage is to declare the structures needed by "geometry" in the open clause of the structure declaration for "geometry".  The main reason to declare the needed structures is to permit static analysis of the dependencies among structures.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 Darwin does no static dependency analysis today.  As structures are opened, all dependent structures are opened.  However, one of the benefits of a robust module system is that it is amenable to static dependency analysis.  This is a benefit because it affirms the predictive power obtained by using the module system:  A module depends only on the structures listed in the open clause and no others.  This fact enables separate compilation of modules as well as predictable run-time behavior of modules, whether they are compiled or not.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {See the section "Initializers of package-specific data" for a discussion.}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain{\pntext\pard\plain\fs40\f0 3.\tab}{\*\pn\pnlvl1\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs40\pnf0}\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0 {Discussion}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 3.1.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Initializers of package-specific data}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Darwin promotes the run-time sharing of loaded package code.  When a structure {\i\ul0 foo }is declared and loaded, it can be used in many other packages and yet only one copy of the functions (and data) of {\i\ul0 foo }exists in the Lua state.  Any variables over which the functions of {\i\ul0 foo }are closed (i.e. any "upvalues") are therefore shared by all users of {\i\ul0 foo.  }Since so many modules are stateless (containing no closures), this sharing property is often irrelevant.  And when there are closures, sometimes the sharing behavior is in fact the expected behavior.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Consider a structure that contains a factory function, where every object produced by the factory has a unique serial number.  A simple implementation would be to use a counter function implemented as a closure over a variable holding the previous count.  No matter how many packages use the (same) factory, each package will receive objects with unique serial numbers, since the counter is shared.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {For another example, consider a structure that maintains a pool of reusable objects, such as buffers or processes.  The sharing behavior is the expected behavior:  There is one instance of the structure and the pool is shared among the various users of the package.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {However, there are times when a module's functionality requires that some data structures exist on a per-user basis.  In other words, each user of the structure should see its own data set, and the functions in the module should operate on the data set of the caller.  This is a classic factory design pattern, and it is not made transparent by Darwin.  The module should be written to export a factory function that produces (and initializes) the needed data structures.  The user of the module must call the factory before using module functions that need the data.  Usually, the object produced by the factory is supplied as an argument to factory functions.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Consider again the example definition of the {\i\ul0 user }package (see the section "Declaration of the user package").  In this case, the per-user data is the {\i\ul0 package }table, and it is a singleton.  That is, a user of the {\i\ul0 package }module instantiates exactly one {\i\ul0 package }table.  Also, the package table has a standard location in th environment, namely the table called {\i\ul0 package. } Consequently, {\i\ul0 package.initialize }does not need to return a value, and the package table does not need to be supplied as an argument to functions like {\i\ul0 require.}  Because there is only one {\i\ul0 package }table, the {\i\ul0 package }module is written to store it in a well-defined place (a table called "package" in the current structure environment), and the module functions (like {\i\ul0 require}) are written to look for it there. }
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 3.2.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {What makes a good module?}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Taken as a general question, the answer is out of scope for this document.  However, there are some technical considerations to keep in mind when creating Lua modules with Darwin.   We will examine these considerations using a case analysis on the type of the value being exported from a module.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {First, note that modules typically export functions.  Because each user of a module function in Darwin has a binding to the same function, any state held by the function will be shared across users.  For example, a simple counter object can be made by creating a closure over a private index variable.  (In Lua terminology, the index variable is an {\i\ul0 upvalue}{\i\ul0  }of the counter function.)  Suppose such a counter is defined in a Darwin structure called {\i\ul0 counter.}  Two modules that both use {\i\ul0 counter }will get unique values because there is only one counter function, and it has one index variable as its upvalue.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Next, let's look at tables.  By default, when a structure exports a table, Darwin creates for the user a deep copy of that table.  This seems to be the right thing to do when the table contains functions or tables of functions (etc.) because in most cases the module writer wishes to export those functions.  However, as we have already seen, a table in Lua might implement an object (with state and methods) rather than just being a collection of functions.  To accommodate this case, Darwin provides the {\i\ul0 objects }clause in {\i\ul0 structure.declare.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When a structure is opened and Darwin encounters an object in that structure, Darwin does exactly what it does for functions:  it creates a binding for that table (object) in the destination environment, the place where the structure is being opened.  In this case, the table (object) is a single instance that is shared between all users of the structure.  Unlike functions, though, tables are writable.  Altering a shared table (object) alters it for all the users of the structure that exports the table (object).  Keep this in mind when exporting objects.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Finally, exporting scalars has virtually no utility.  Suppose a structure {\i\ul0 x} exports a binding named {\i\ul0 foo} that is bound to a scalar value, which in Lua includes numbers, strings, and booleans.  Any structure that opens {\i\ul0 x} receives a copy of the binding of {\i\ul0 foo.  }In other words, when you open {\i\ul0 x}, you get a binding of the name {\i\ul0 foo }to a scalar value, e.g. 5 or "hello".  The code of the structure {\i\ul0 x} cannot modify this binding.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The binding that the user sees for {\i\ul0 foo }did not exist when the structure code was loaded, so there is no way for the structure code to access the user's binding for {\i\ul0 foo.  }Now, the structure code might modify its own binding for {\i\ul0 foo, }which is the binding in the structure environment.  That binding is not visible to the user.}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\cf6\ul0 A diagram here would really help.}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We have a situation in which (1) the code in structure {\i\ul0 x} can write to its own binding for {\i\ul0 foo, }which cannot be read by the user; and (2) the code in structure {\i\ul0 x }cannot write to the user's binding for {\i\ul0 foo, }which can be read by the user.  In other words, the structure code and the user code cannot communicate through scalar bindings.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {It appears that the only use case for exporting scalar values is to make constants readable to the user code.  For example, the {\i\ul0 math }package exports {\i\ul0 math.pi.  }The same reasoning can be applied to a structure that exports some data about how it is configured, e.g. a matrix package might export {\i\ul0 matrix.}{\i\ul0 maximumdimension}{\i\ul0 .}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {To share state between all users of a structure, you can export a binding to container (which in Lua means a table).}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {To provide private state to each user of a structure {\i\ul0 x,} the "factory" pattern should be used.  To follow this approach, {\i\ul0 x} should export a "factory function" that creates new instances of whatever private state is needed.  Each user of {\i\ul0 x} must call the factory, which returns some object.  In some cases, such as Darwin's implementation of the {\i\ul0 package }table, the factory is only called once by each user.  In that case, the factory could simply be named {\i\ul0 initialize.  }In other cases, such as in a graphics rendering environment, a factory function might produce canvases, and the user code would call the factory each time it wanted to create a new canvas.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 3.3.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Darwin's require, module, and seeall functions}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Darwin was designed to be independent of Lua's module system, but to work with it.  Within a Darwin package, the Lua module capabilities behave just as they do without Darwin.  That is, the {\i\ul0 package }table and the {\i\ul0 require }and {\i\ul0 module }functions work as expected, except their scope is no longer global \emdash  it is limited to the environment of the package in which they execute.  This feature of Darwin allows existing code to be used without the need to declare any Darwin structures for it.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Moreover, because the existing Lua module code is confined to the package in which it is loaded, the existing code cannot inadvertently affect other Darwin packages.  Any odd effects of using existing Lua module code (namespace collisions, namespace leaks, etc.) can still occur, but only locally, in the package in which the existing code is used.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In order to achieve this isolation for Lua's module system, Darwin provides its own implementation (in Lua) of the {\i\ul0 require, module, }and {\i\ul0 package.}{\i\ul0 seeall}{\i\ul0  }functions.  The plain Lua versions of these functions are closed over a single global environment (LUA_GLOBALSINDEX) and a single {\i\ul0 package} {\i\ul0 loaded} table (stored in the LUA_REGISTRYINDEX at "_LOADED").  The Darwin versions of {\i\ul0 require, module, }and {\i\ul0 seeall}{\i\ul0  }are intended to be faithful ports of their C language counterparts into Lua, with only one difference:  The Darwin versions access the {\i\ul0 package }table from the current structure environment.  The result is that each Darwin package has its own {\i\ul0 package }table.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {By default, Lua's module capabilities do not interact with the Darwin system.  As we saw earlier in the section called "Darwin and Lua's package table", however, the two can be easily linked so that Lua's {\i\ul0 package.loaded }table will reflect open structures, and Lua's {\i\ul0 package.}{\i\ul0 preload}{\i\ul0  }table will reflect available structures that can be opened.  Observe that this linkage (via metatable index) is on a per-package basis.  The Darwin user can choose for some packages to open the structure {\i\ul0 modname}{\i\ul0  }when {\i\ul0 require(}{\i\ul0 modname}{\i\ul0 ) }executes, and for other packages to ignore the structure {\i\ul0 modname}{\i\ul0 , }in which case {\i\ul0 require }functions as it does in plain Lua.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In all cases, the Darwin design goal remains to give the user full control of the environment in which code runs.  }
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 3.4.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Darwin modules and garbage collection}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Darwin module declarations and instances (i.e. loaded modules) will not be collected unless the module is deleted with {\i\ul0 structure.delete}.  Deletion of structure {\i\ul0 x }does not affect the instances created by other structures which have already opened structure {\i\ul0 x}.  If the declaration is deleted, then no other structure can open the module.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {For a short discussion of collection of unneeded bindings, see the "Weak imports" sub-section of the section called "Planned enhancements".}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 3.5.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Searching for structure declarations}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {We do {\b\ul0 not} recommend using any mechanism that searches the file system for structure declarations.  The loading of declarations is meant to be a kind of administrative task in which the run-time environment for code is defined (and constrained).  It would weaken the assurances provided by the Darwin module system if structure declarations were "found", because they could specify anything \emdash  even opening up security holes or in general allowing undesired capability leaks.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The intended use of Darwin in a production system is that Darwin will be loaded first, and Darwin finishes by establishing the environment that will hold user code.  This is the {\i\ul0 user }structure by default.  Next, one or more files containing structure declarations are loaded.  Finally, user code is loaded into the environment crafted especially to contain the user code.  The user code runs in as free or as constrained an environment as is established for it.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In a production system in which there is no additional "user" code loaded, the {\i\ul0 user }structure may not be needed at all.  Or, the {\i\ul0 user }structure can contain the "driver" code that starts the system running with the right input parameters.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 3.6.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Note on starting Darwin}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The Lua command line accepts an argument to load libraries, and so "-ldarwin" may be specified on the command line.  For interactive sessions, the command "lua -ldarwin -i" achieves the right effect.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The LUA_INIT environment variable can also be used to load Darwin.  See the documentation for the Lua command for more information.}
\par\pard\plain\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain{\pntext\pard\plain\fs40\f0 4.\tab}{\*\pn\pnlvl1\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs40\pnf0}\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0 {Comparison to other module systems}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 4.1.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Scheme48}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\cf6\ul0 To do.}}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 4.2.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {SML}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\cf6\ul0 To do.}}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 4.3.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Java}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\cf6\ul0 To do.}}
\par\pard\plain\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain{\pntext\pard\plain\fs40\f0 5.\tab}{\*\pn\pnlvl1\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs40\pnf0}\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0 {Darwin Reference}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 There is one part of Darwin with which you need to interact: Darwin provides a set of functions for declaring and manipulating structures.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 If you want to customize the set of initial structures provided by Darwin when it starts, then you need to modify the file }{\i\ul0 "}{\ul0 initialstructures}{\ul0 .}{\ul0 lua}{\ul0 ", which defines all of the initial structures, including the user structure.}}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 5.1.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Functions}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The following table summarizes the functions provided by Darwin.  Key functions are documented further in the subsections that follow.  Most users will only ever use the first 6 functions, and possibly only the first one: {\i\ul0 declare}.}
\par\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Function}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Arguments}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Returns}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Description}}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {declare}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 see below}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 see below}}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {load}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name (string)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 true} (boolean)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 see below}}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {open}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name1, ...}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {environment (table)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {open, loading if necessary}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {close}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name or {\b\ul0 nil}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {close and delete bindings}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {delete}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name or {\b\ul0 nil}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {delete from global structure list}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {signature}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {signature (table) or {\b\ul0 nil}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 see below}}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {isdeclared }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 true} or {\b\ul0 nil}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {is name in global structure list?}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {isloaded}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 true} or {\b\ul0 nil}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {is name loaded?}

\cell\row
\trowd\trgaph60\trql\trrh546\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {isopen}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {environment or {\b\ul0 nil}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {is name open in current environment?}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {currentpackage}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name of current package}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {currentenvironment}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {environment}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {environment of current package}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {currentopentable}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {(table)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {analogous to {\i\ul0 package.loaded}}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {preloadtable}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {(table)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 see below}}

\cell\row
\trowd\trgaph60\trql\trrh546\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {instructure}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name [, code]}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {(values)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 see below}}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {declared}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {(table)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {list of declared structures}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {getpath}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {(string)}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {search path for {\i\ul0 files }clause}

\cell\row
\trowd\trgaph60\trql\trrh547\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {setpath}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {path}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\emdash  }

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {set the {\i\ul0 files }search path}

\cell\row
\trowd\trgaph60\trql\trrh345\trleft20\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx2246\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx3890\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx6290\clbrdrt\brdrs\brdrw20\brdrcf1\clbrdrl\brdrs\brdrw20\brdrcf1\clbrdrb\brdrs\brdrw20\brdrcf1\clbrdrr\brdrs\brdrw20\brdrcf1\cellx9825 \pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {initialize}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {name}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 true}}

\cell\pard\plain\intbl\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\i\ul0 see below}}

\cell\row\pard
\par\pard\plain\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 5.1.1.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {To declare one or more structures, call structure.declare with a table argument.  Multiple structures that share an implementation can be declared at once, in order to provide different "views" on the same underlying code.  The table entries in a structure declaration are called {\i\ul0 clauses,} and there are two categories of clauses: Name/signature/location clauses, and code clauses.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Name/signature/location clauses}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When declaring multiple structures, you must provide a {\i\ul0 structures }clause whose value is a table of name/signature/location clauses, e.g.}
\par\pard\plain\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \{ structures= \{ \{ name="tableprint",}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    signature=\{"tprint", "tprintf", "tdump"\} \};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                  \{ name="tableprint_min",}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    signature=\{"tprint"\},}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    location="." \};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                  \{ name="tableprint_full",}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                    location="tableprint" \};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {                \};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    open=\{"_G", "table"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {    files=\{"tableprint.lua"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {  \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In this example (above), three structures are defined.  They are three different views of the same code.  They literally share the same code, i.e. the file "tableprint.lua" is loaded once.  Users of tableprint may open any of the declared structures: "tableprint", "tableprint_min", or "tableprint_full".  Opening "tableprint" yields the three functions listed in the "tableprint" signature: {\i\ul0 tprint}{\i\ul0 , }{\i\ul0 tprintf}{\i\ul0 , }and {\i\ul0 tdump}{\i\ul0 .}  Since there is no location clause for "tableprint", these functions will be located in a table with the same name as the structure, i.e. {\i\ul0 tableprint}{\i\ul0 .}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {By contrast, opening "tableprint_min" yields just one function, {\i\ul0 tprint}{\i\ul0  }(the one name listed in the signature for "tableprint_min").  And {\i\ul0 tprint}{\i\ul0  }will appear in the global environment, as specified by the location value "." for "tableprint_min".}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Finally, "tableprint_full" provides the entire set of global bindings from the file "tableprint.lua", because no signature is specified.  Presumably, there are more functions than the ones already named.  Perhaps there are some functions or objects that are used to configure how tables are printed by default with {\i\ul0 tprint}{\i\ul0 .}  When "tableprint_full" is opened, all of the global bindings from the file "tableprint.lua" will be visible in the {\i\ul0 tableprint}{\i\ul0  }table of the global environment (again due to the location clause, which overrides the default behavior of naming the table after the structure, which in this case would be {\i\ul0 tableprint}{\i\ul0 _full}).}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Darwin's declare function allows a syntactic shortcut to be taken when declaring only one structure, which is the most common case.  The shortcut is to drop the {\i\ul0 structures }clause entirely, and put the {\i\ul0 name, signature, }and {\i\ul0 location }clauses at the top level of the declaration.  The other examples in this document use that more compact syntax.  Remember that {\i\ul0 signature }and {\i\ul0 location }are optional.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 Code clauses}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A set of "code clauses" specify the code that creates a Darwin structure.  All of the code clauses are optional, and they may be used in any combination.  The following list defines each clause; the list reflects the order in which Darwin processes code clauses when loading a structure.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 1.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 open=\{m1, ...\} } {\i\ul0 Starting with an empty environment, Darwin opens each of the structures m1, ... in order.  If two or more structures export the same name to the same location, a warning is displayed and the last binding will be used.}}
\par\pard\plain{\pntext\pard\plain\fs20\f0 2.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 pre}{\b\ul0 ="..."}  {\i\ul0 When present, this string value is evaluated as code in the current structure environment, i.e. an environment in which m1, ... are open.}}
\par\pard\plain{\pntext\pard\plain\fs20\f0 3.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 files=f1} {\i\ul0 or }{\b\ul0 files=\{f1, ...\}}  {\i\ul0 The files clause accepts a single string or a list of strings as a value.  Each string is a file name or part of a file name.  Following the pattern established by Lua's path and }{\i\ul0 cpath}{\i\ul0  variables, Darwin looks for f1, ... by substituting f1 (and the others in turn) for the '?' character in each part of the Darwin path (see below).}}
\par\pard\plain{\pntext\pard\plain\fs20\f0 4.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 post="..."}  {\i\ul0 When present, this string value is evaluated as code in the current structure environment, i.e. the environment after the files clause is processed.}}
\par\pard\plain{\pntext\pard\plain\fs20\f0 5.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 environment="..."}  {\i\ul0 When present, this string value is evaluated as code in the current structure environment, i.e. the environment after the post clause is processed.  The environment code must return a table.  That table becomes the structure environment.  It is from this table that bindings are copied when the declared structure is opened in another module.  When the environment clauses is absent, the structure environment is the environment that was present after the last code clause was processed, whether it was the post clause, the files clause, the }{\i\ul0 pre}{\i\ul0  clause, or the open clause.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The Darwin path variable specifies how Darwin finds files that are listed in the files clause.  You can examine the variable by called structure.getpath() and set the variable by calling structure.setpath(newpathstring).  Here is an example showing the default value and how to change it.  Note that the default path is created from Lua's package.path.  The ".lua" extension is removed from each pattern, and "?;" is prepended so that Darwin will first treat a file name as if it were an absolute file name, and only if that fails will other options be considered.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Darwin 1.0.2 Copyright (c) 2009 James S. Jennings}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {Current package is 'user'.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.getpath()}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =structure.getpath()}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {?;./?;/usr/local/share/lua/5.1/?;/usr/local/share/lua/5.1/?;/usr/local/lib/lua/5.1/?;/usr/local/lib/lua/5.1/?}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.setpath("?")}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =structure.getpath()}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {?}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 5.1.2.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {structure.load}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The {\i\ul0 load} function, like most of the functions exposed in {\i\ul0 structure}, is not normally needed when using Darwin.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Structure declarations are lazy in that they do not execute the code that is specified in their code clauses.  Instead, that code is executed when a structure is opened for the first time.  The process of executing the code specified in the code clauses, which creates the structure environment, is called "loading" the structure.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A structure is only loaded once, i.e. the code specified by the code clauses is executed only once, ever.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The {\i\ul0 load }function is provided so that you can control when a structure is loaded, if you wish.  Loading a structure does not also open it.  The argument to {\i\ul0 load }is a structure name, and the return value is always {\b\ul0 true }(else an error is thrown).}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 5.1.3.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {structure.signature}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The {\i\ul0 signature }function takes a structure name as its argument and returns a (fresh) table that is an array{\super \chftn {\footnote {\super \chftn \pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In this document, an "array" is a table whose (non-nil) values are stored in a contiguous set of integer keys starting with 1.}
}}} of the names of the bindings exported by that structure.  The array returned by {\i\ul0 signature }is essentially a copy of the actual structure signature.  Therefore, you cannot modify the signature of a structure using this function.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {See {\i\ul0 structure.declare }to learn how a single structure environment can be the basis for several different structures, each with their own signature.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Note: {\i\ul0 signature }returns nil if and only if a structure is declared without an explicit signature and the structure has not been loaded.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 5.1.4.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {structure.currentopentable}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {This function returns the table of structures which are currently open, i.e. open in the current structure.  The table has the same format as Lua's {\i\ul0 package.loaded.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\b\ul0 N.B. }This table is the actual table used by Darwin.  Modifying its contents will produce unexpected and probably undesirable behavior.  {\i\cf6\ul0 This is a weakness that will be addressed in a future release.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The table of open structures returned by {\i\ul0 currentopentable}{\i\ul0  }has one intended use:  By setting the {\i\ul0 __index }meta-method on {\i\ul0 package.loaded }to this table, Lua's {\i\ul0 require }function will see all of the open structures.  Therefore, {\i\ul0 require(x) }will return {\i\ul0 currentopentable}{\i\ul0 [x] }if {\i\ul0 x} is not already in {\i\ul0 package.loaded.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The code example below is the Darwin declaration for {\i\ul0 user }structure (which may be customized as you wish).  This declaration opens some of the standard libraries and also links {\i\ul0 package.loaded }to the current open table and {\i\ul0 package.}{\i\ul0 preload}{\i\ul0  }to the table of declared Darwin structures.  (See {\i\ul0 structure.}{\i\ul0 preloadable}{\i\ul0  }for more information on the latter.)}
\par\pard\plain\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \{ name="user"; }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab open=\{"_G", "structure", "package", "debug", "table", }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab  "io", "os", "string"\};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab pre=}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab [[ package.initialize();}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab    setmetatable(package.preload, \{__index=structure.preloadtable()\})}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab    setmetatable(package.loaded,\{__index=structure.currentopentable()\})}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab ]];}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \}}
\par\pard\plain\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 5.1.5.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {structure.preloadtable}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The {\i\ul0 preloadtable} function is similar to the {\i\ul0 currentopentable}{\i\ul0  }in that it is provided only to enable a linkage between Darwin and Lua's {\i\ul0 require }function.  Since {\i\ul0 require }uses the loaders in {\i\ul0 package.loaders, }and the first entry in that table is (by default) a function that looks in {\i\ul0 package.}{\i\ul0 preload}{\i\ul0 , }Darwin provides a "preload table" of its own that has the same format as the first default loader expects to find in {\i\ul0 package.}{\i\ul0 preload}{\i\ul0 :  }Each key is a structure name, and each value is a function which provides that structure.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In the Lua terminology, the loader function found in {\i\ul0 package.}{\i\ul0 preload}{\i\ul0 [x]} "loads" the module {\i\ul0 x.}  In the Darwin terminology, the function found in {\i\ul0 preloadtable}{\i\ul0 ()[x] }"opens" the structure {\i\ul0 x}, loading it if necessary.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {In fact, every entry in {\i\ul0 preloadtable}{\i\ul0 () }has the same value, which is the function {\i\ul0 structure.open}.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {See the example in {\i\ul0 structure.}{\i\ul0 currentopentable}{\i\ul0  }to see how the table returned by {\i\ul0 preloadtable}{\i\ul0  }is intended to be used.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Note that you don't need {\i\ul0 preloadtable}{\i\ul0  \emdash  }you can simply add entries to {\i\ul0 package.}{\i\ul0 preload}{\i\ul0  }in order to enable Lua's {\i\ul0 require }function to automatically open declared structures.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 5.1.6.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {structure.instructure}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {This function is only for use during development and debugging.  It allows you to break through the walls that separate structures and execute code in the environment of another structure.  With {\i\ul0 instructure}{\i\ul0 , }you can run code in another structure's environment and you can change the structure of the current thread to another structure.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The first argument is a structure name, and the second argument is a string that will be evaluated as code in the environment of the named structure.  There are three common scenarios during development that can be addressed with {\i\ul0 instructure:}}
\par\pard\plain{\pntext\pard\plain\fs20\f0 1.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {To retrieve a value directly from the structure environment, as shown in the transcript example below, where we accidentally removed our binding to {\i\ul0 dofile}{\i\ul0 , }but we got it back by accessing the binding in the {\i\ul0 _G} structure.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 2.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {To access an unexported binding from a structure's environment, which is useful when debugging.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 3.\tab}{\*\pn\pnlvlbody\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {To modify values (including function definitions) in the structure environment \emdash  but in general you will have to {\i\ul0 close }the structure and then {\i\ul0 open }it again in order to see the effects of the change.}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> dofile=5}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =dofile}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {5}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> dofile=structure.instructure("_G", "return dofile")}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =dofile}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {function: 0xe32700}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 In this example, we show the other use of }{\i\ul0 instructure}{\i\ul0 , }{\ul0 which is to change the environment to one of another structure.  Note that the prompt changes when entering the }{\i\ul0 config}{\i\ul0  }{\ul0 structure.  This is due to the statement }{\i\ul0 _PROMPT="}{\i\ul0 config}{\i\ul0 > "}{\ul0  in the file "}{\ul0 initialpackages}{\ul0 .}{\ul0 lua}{\ul0 ".  When developing and debugging, this is a very useful trick that you can use with your own structures as you wish.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.instructure("config")}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {config> =math}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {table: 0xff85c0}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {config> =structure}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {table: 0x1000ef0}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {config> =originalluapackage}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {table: 0xffa930}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {config> structure.instructure("user") }
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =math}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {nil}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =structure}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {table: 0x1020140}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =originalluapackage}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {nil}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 5.1.7.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {structure.initialize}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 The }{\i\ul0 initialize }{\ul0 function initializes Darwin.  You can see how it is used by looking in the file "}{\ul0 initialstructures}{\ul0 .}{\ul0 lua}{\ul0 ", which is discussed later in this document.  Darwin takes the initial environment (the one into which Darwin is loaded) and turns it into a structure.  The name of that structure is the argument to }{\i\ul0 initialize.}{\ul0   Darwin's default configuration names this structure "}{\ul0 config}{\ul0 ".  The "}{\ul0 config}{\ul0 " structure is really just a container for everything that's there when Darwin is loaded,    and this structure is not meant to be accessed except, perhaps, during debugging.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 An attempt to }{\i\ul0 open }{\ul0 the initial package will throw an error.}}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 5.2.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {darwin.initialstructures}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The file "initialstructures.lua" contains the declarations for all of the structures that will be available when Darwin finishes loading.  This file initializes Darwin, defines the signatures of {\i\ul0 structure }and {\i\ul0 _G, }converts the standard libraries into structures, and declares the {\i\ul0 user }structure.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The file "darwin.lua" {\ul0 switches the running thread into the }{\i\ul0 user }{\ul0 structure and prints a copyright and version number for Darwin.}}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\ul0 Customizing "}{\ul0 initialstructures}{\ul0 .}{\ul0 lua}{\ul0 " allows you to create whatever set of structures you want to be available after Darwin loads.  E.g. you can restrict the signature of }{\i\ul0 structure }{\ul0 to expose fewer functions; you can omit or add libraries in the set of initial structures; etc.}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain{\pntext\pard\plain\fs40\f0 6.\tab}{\*\pn\pnlvl1\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs40\pnf0}\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0 {Known bugs, limitations, and planned enhancements}
\par\pard\plain\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 6.1.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Known bugs}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {None.  Surely there are bugs.  Just not {\i\ul0 known }bugs.  Yet.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 6.2.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Limitations}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 6.2.1.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {Code change needed to support MacOS}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Darwin's versions of some of the functions in {\i\ul0 package.loaders }will fail on MacOS.  The reason is that Lua's {\i\ul0 package.}{\i\ul0 config}{\i\ul0  }string does not provide all of the characters needed to replicate the functionality of the functions in the Lua {\i\ul0 package }library (which are implemented in C).}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Here is an excerpt from the file "darwinpackage.lua":}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local DIRSEP = string.sub(originalluapackage.package.config, 1, 1)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local PATHSEP = string.sub(originalluapackage.package.config, 3, 3)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local PATHMARK = string.sub(originalluapackage.package.config, 5, 5)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local EXECDIR = string.sub(originalluapackage.package.config, 7, 7)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local IGMARK = string.sub(originalluapackage.package.config, 9, 9)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {-- These values are #defined and should be part of package.config}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local OFSEP = "_"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {local POF = "luaopen_"\tab \tab -- !@#  NOT PORTABLE, e.g. on MacOS will fail}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {As you can see, the last two items, {\i\ul0 OFSEP}{\i\ul0  }and {\i\ul0 POF}{\i\ul0 , }are not part of Lua's {\i\ul0 package.}{\i\ul0 config}{\i\ul0 .}  It's possible for Darwin to make a run-time check to determine the OS type, but that would require either a special library or at least the use of the {\i\ul0 os}{\i\ul0  }package, which may or may not be present in a given installation.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\cf6\ul0 Note: A work-around, such as a run-time check, should be added to Darwin so that }{\cf6\ul0 MacOS}{\cf6\ul0  users will not have to edit "}{\cf6\ul0 darwinpackage}{\cf6\ul0 .}{\cf6\ul0 lua}{\cf6\ul0 " in order to try out Darwin.}}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 6.2.2.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {No explicit support for renaming exports}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Some module systems, like the one in Scheme48, provide a way to export a binding under a different name, or even to rename all the exported bindings (e.g. by adding a prefix string).  Darwin could, but does not, provide such a feature.  Because Lua uses tables for environments, operations such as renaming can always be done within a structure declaring by supplying a {\i\ul0 post }code clause containing code that operates directly on the environment.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {For example, consider the following declaration:}
\par\pard\plain\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 CODE EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {structure.declare}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \{ name = "verbose_trigonometry";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab location = "vmath";}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab signature = \{ "sine", "cosine", "tangent" \};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab open = \{ "math" \};}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab post = [[ sine = math.sin;}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab cosine = math.cos;}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab \tab tangent = math.tan;}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \tab \tab \tab \tab ]];}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {\tab \}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {With this declaration, we can use verbose names for the trigonometry functions as follows:}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {{\f0\b\ul0 TRANSCRIPT EXAMPLE}}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> structure.open "verbose_trigonometry"}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =vmath.sine(3.1416/4)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {0.70710807985947}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> =vmath.tangent(3.1416/4)}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {1.0000036732118}
\par\pard\plain\s9\ql\li720\ri720\fi0\keep\tx0\tx280\tx560\tx860\tx1140\tx1440\tx1720\tx2000\tx2300\tx2580\tx2880\tx3160\tx3440\tx3740\tx4020\tx4320\tx4600\tx4880\tx5180\tx5460\tx5760\tx6040\tx6320\tx6620\tx6900\f1\fs20\i0\b0\cf1\ul0\strike0 {> }
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Recall that the {\i\ul0 location }clause of a structure declaration is used to relocate a structure's exports to a different table name or to top-level.  If we wanted to build a variation of the {\i\ul0 math} package that exported different function names (such as the verbose ones in the example above), we would write {\i\ul0 location="math" }in our structure declaration.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 6.2.3.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {No explicit support for importing a subset of bindings}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {At times, you may wish to import only a subset of the bindings exported by a package.  For example, your code for binary search might use the function {\i\ul0 math.floor, }so the structure containing your code must open the {\i\ul0 math }structure.  Although you only need one that one function, you will get a copy of all of the bindings in {\i\ul0 math.  }While these do not take up much space, the unneeded bindings are indeed wasting space which may be scarce.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Following the example in the previous section, you can devise a work-around in which you define a structure whose only export is the {\i\ul0 math.floor} function.  However, it would be convenient if Darwin provided a way to import a subset of the bindings exported by another structure.  This is the subject of the one of the planned enhancements below.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs32\f0 6.3.\tab}{\*\pn\pnlvl2\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs32\pnf0}\s3\ql\fi0\f0\fs32\i0\b\cf1\ul0\strike0 {Planned enhancements}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Over and above the weaknesses already noted in this document, the following sections mention in brief some planned enhancements to Darwin.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 6.3.1.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {A Meta-Module Protocol?}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {There are many similarities between a module system and an object system.  For example, the dependency graph among a set of modules is like the inheritance graph of classes in a class-based object system with multiple inheritance.  Other similarities derive from that observation, such as the parallel between method lookup and choosing the right binding when there are multiple choices.  (In Darwin today, it is illegal to import the same name from multiple packages, although this is not detected in the current implementation.)}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {There appears to be some opportunity to apply the concept of a meta-object protocol here.  {\i\ul0 (Cite }{\i\ul0 AMOP}{\i\ul0  here.)}  The result would be a module system whose properties could be altered by the module designer, i.e. the person building modules for use by themselves and others.  Because Darwin can run inside of Darwin, we are already prepared for enabling one designer's customized module rules to co-exist with other modules that have the default (or some other) behavior.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Behaviors that might be customizable with such an enhancement include such things as:}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Post-processing of the table of bindings produced when a structure is opened.  A custom function plugged into Darwin for post-processing could make the table weak (see "Weak imports" below); or it could perform per-user initialization steps; etc.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A customizable file search function (or table of functions, like {\i\ul0 package.loaders}) could replace the current search path capability.  The default search function could, of course, be the exactly the path-based searcher that is in Darwin today.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {If a custom wrapper around {\i\ul0 structure.open }procedure could be inserted, then Darwin could be extended by its users to do things like allow aliases for structure names, allow "compound structure names" (where one name stands in for several structures), etc.  A custom wrapper for {\i\ul0 open }would also facilitate run-time checking of access rights to a structure, so that access permissions could be declared.}
\par\pard\plain{\pntext\pard\plain\fs20\f0 *\tab}{\*\pn\pnlvlblt {\pntxtb \bullet}{\pntxta  }\pnstart1\pnindent0\pnhang\pnfs20\pnf0}\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Etc.  The examples above illustrate the idea, and it is easy to take this idea and run with it.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 6.3.2.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {Weak imports}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When a structure, {\i\ul0 x, }is opened, the user gets a copy of the bindings exported by {\i\ul0 x}.  However, the structure that uses {\i\ul0 x} may not use all of the bindings exported by {\i\ul0 x.  }The Lua mechanism of weak tables can be employed to automatically remove (during garbage collection) all imported bindings that are not used.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The implementation would require another declaration clause that indicates which structures should be {\i\ul0 weakly opened.  }When you open such a structure, you will get a weak table of bindings whose values will be removed by the garbage collector when they cannot be accessed from your code.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The benefit of this approach is that you do not need to declare which functions of {\i\ul0 x }you are going to use.  You use the ones you need, and the bindings for the rest will be collected.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The disadvantage to this approach is that "reflective code" can fail.  By "reflective", I mean code that examines its own environment, e.g. {\i\ul0 f=_G[name].}  Since the value of the variable {\i\ul0 name }cannot, in general, be known, this assignment statement may access any entry in {\i\ul0 _G.}  If the author of this statement assumed that {\i\ul0 _G} would forever contain exactly the elements that were there when {\i\ul0 _G }was imported, then she may be surprised to learn that the garbage collector removed unused bindings.  In other words, if {\i\ul0 name }is the name of a function which is not otherwise used in the author's code, then it is not able to be accessed except through {\i\ul0 _G.  }If {\i\ul0 _G }were a weak table, such a binding would be collected.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {If weak environments are supported, then Darwin will support a way to avoid this behavior and obtain regular (non-weak) tables when needed, so that "reflective code" will work as expected.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 6.3.3.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {Support for importing a subset of bindings}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A slightly different use case can be solved with a declaration that tells Darwin that you want only a subset of the bindings of structure {\i\ul0 x, }and not all of them.  Here, the use case may be motivated by conservation of memory, but there is a more general reason.  Examining declarations statically, one can see the dependencies between structures.  For static analysis, we want an explicit declaration that structure {\i\ul0 x} is opened but only some of its bindings are used.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Static dependency analysis could be used for a variety of purposes, but a simple one is to identify commonly-needed subsets of a structure.  A commonly-used subset of a structure is a candidate to become a separate structure.}
\par\pard\plain\par\pard\plain{\pntext\pard\plain\fs24\f0 6.3.4.\tab}{\*\pn\pnlvl3\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs24\pnf0}\s4\ql\fi0\f0\fs24\i0\b\cf1\ul0\strike0 {Functors}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A powerful feature of the SML module system is the concept of a {\i\ul0 functor.  }A functor is a function that accepts modules as arguments and produces a module.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {When functors are explained in the SML literature, a common example arises when you have a choice of data structures to use in your code (as you write a module), and so you decide to write a {\i\ul0 parameterized module} which takes another module as an argument.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {For example, suppose I am implementing a module that renders three-dimensional geometric shapes on a two-dimensional canvas such as a computer screen.  I need a fairly standard set of matrix operations in order to write my code.  Suppose I can use any library that lets me create, multiply, invert, and take the determinant of matrices.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {If I write my rendering module to accept a matrix module as an argument, then my rendering module can be instantiated (declared, in Darwin terminology) with a matrix module supplied at declaration time.  Of course, the matrix module must support the needed operations, and use the expected names for those functions.  (But we know how to write a declaration that renames exports, so the latter is not really an issue.)}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {With this approach, when I declare my rendering module as a Darwin structure, I must supply a matrix structure as an argument.  Today, I will use the basic matrix module I wrote for myself, which is not optimized in any way.  In the future, when my rendering module is working correctly and has all of the functions I need, I may look for a faster matrix module that can substitute for the one I use today.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {I change the declaration of my module, supplying a new matrix module as the argument, and I get a version of my module that uses the new matrix code.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {It is possible to get {\i\ul0 almost exactly }this effect using Darwin today, without functors.  You can declare that Darwin opens the {\i\ul0 matrix }module, and then use different declarations for {\i\ul0 matrix }at different times.  Today, my {\i\ul0 matrix }structure declaration would refer to my own code, but tomorrow I can replace the declaration for {\i\ul0 matrix }with one that refers to a new library that I obtained from someone else.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The difference, at least in this example, is subtle and not especially compelling.  But consider a different scenario, in which we have a module that implements a fairly generic capability such as lexicographic sorting.  A sorting module needs objects to sort.  We might want to sort vectors one day, strings another day, payroll records the next day, etc.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {If the sorting module is parameterized, i.e. it accepts another module as a parameter, then we can make a "payroll record sorting module" by providing the payroll module as the argument.  Similarly, a "vector sorting module" can be made by providing a vector module as the argument.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {The sorting module will require that its argument (e.g. the payroll module) supports the set of functions needed to do sorting, such as a comparison function that maps payroll records {\i\ul0 A }and {\i\ul0 B }to true if and only if A precedes B.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Using a parameterized sorting module (a functor), we can have a system in which modules which do no sorting can open the "plain" payroll module, and modules that do sorting can additionally open a module produced by the sorting functor which provides the capability to sort payroll records.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Similarly, exactly the same sorting functor can be applied to a vector module to produce a module that sorts vectors.  Etc.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Note that, in SML, the power (and the complexity) of functors is more apparent because of SML's sophisticated type system.  Even though type-related benefits would not materialize for Lua, it is possible that the ability to parameterize a module will be useful nonetheless.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Consider the ability to parameterize a module with arguments that are not other modules.  For example, a "logging level" parameter could be provided when a Darwin structure is declared.  This is a declaration-time action that can affect what the module code does when it is loaded.  The module code could, for example, examine the logging level parameter and use it to conditionally define functions.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {A module declared with a logging level of zero might be much smaller (in memory) and faster than the same module declared with a high logging level.}
\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Other "compile-time" optimizations are possible in this way.  For example, a matrix module could take a "maximum dimension" parameter in its declaration.  Depending on the maximum dimension, the module might choose one implementation over another for some functions.  For example, determinants can be very quickly calculated in 3 dimensions without resorting to a generic algorithm that works on higher dimensional matrices.}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {\page}
\par\pard\plain{\pntext\pard\plain\fs40\f0 7.\tab}{\*\pn\pnlvl1\pnprev1\pndec{\pntxtb  }{\pntxta . }\pnstart1\pnindent0\pnhang\pnfs40\pnf0}\s2\ql\fi0\f0\fs40\i0\b\cf1\ul0\strike0 {Bibliography}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {{\cf6\ul0 To do.}}
\par\pard\plain\par\pard\plain\s0\ql\fi0\sa200\f0\fs20\i0\b0\cf1\ul0\strike0 {Cite AMOP, Scheme48, SML, Java, "Java Has No Module System"}
\par\pard\plain}
