Working with multiple files · Coding Class
This topic is not available in the selected language or version. Showing the start of this section.
Apply the chapter in three steps: an exercise, a program project, and a debugging task. Implement first, then consult the hints and completion criteria. Use a separate file or working directory for each task.
1. Exercise · Map paths to modules
Section titled “1. Exercise · Map paths to modules”Write module declarations for app.xen, shop/model.xen, and shop/view.xen, and the import needed for view to use model.
Completion: app, shop.model, and shop.view match the paths; view imports model directly.
Hint: An import in app does not introduce names in view.
2. Build a program · Build a shop total
Section titled “2. Build a program · Build a shop total”Start from the chapter’s three files. Create model.Item values for tea priced 3 and bread priced 5. Print tea: 3 and bread: 5 through view, then total 8 from app.
Completion: xen check app.xen succeeds and output is three lines. Define Item only once, in model.
Hint: Keep display functions and data declarations in their respective modules.
3. Debug · Fix a module declaration mismatch
Section titled “3. Debug · Fix a module declaration mismatch”A file at shop/model.xen begins with module model;. Import it from the chapter’s app, check the project, and fix the declaration.
Completion: Checking succeeds without moving the file or changing the import path.
Hint: Reflect the path with module shop.model;.
Verify and record
Section titled “Verify and record”Use xen check file.xen followed by xen run file.xen for ordinary programs; use xen test file.xen for test-only files. Record the original error, its cause, and the corrected result, then rerun every input in the completion criteria.