Skip to content
Xen / docs

Search documentation

English · v0.1.0-demo.2

Type to search the documentation.

    한국어
    Xen / coding-class v0.1.0-demo.2

    Build a word counter · Coding Class

    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.

    Create an empty file, a file containing only spaces/tabs/newlines, and a file containing one two three four . Run the chapter’s word counter on each.

    Completion: The counts are 0, 0, and 4. Count words rather than lines.

    Hint: Count items after splitting the whole file on ASCII whitespace.

    2. Build a program · Build a multi-file report

    Section titled “2. Build a program · Build a multi-file report”

    Accept several paths and print path: count per file. Prepare a.txt with one two and an empty b.txt. Report read failures as path: error and continue.

    Completion: For a.txt, absent missing.txt, b.txt in that order, output is a.txt: 2, missing.txt: error, b.txt: 0.

    Hint: Replace the single-argument check with an index loop and match each count_file result.

    Using the chapter’s single-file version, diagnose and fix xen run word_count.xen input.txt and ./word-count -- input.txt.

    Completion: Correct commands are xen run word_count.xen -- input.txt and ./word-count input.txt; both print the same count.

    Hint: Distinguish the Xen CLI separator from the program’s own arguments.

    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.