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

    Scope modes · 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.

    1. Exercise · Enable references where needed

    Section titled “1. Exercise · Enable references where needed”

    Run two versions of scope_modes.xen from the chapter: annotate all of main, then annotate only the call block.

    Completion: Both print [1, 2, 3] and 10; identify the extent of reference permission in each.

    Hint: Use #![explc] for a function and #scope[explc] for a block.

    2. Build a program · Compare optimization modes

    Section titled “2. Build a program · Compare optimization modes”

    Run the same program with —opt=off and —opt=basic and compare stdout. Also run basic with —opt-report, distinguishing the report from program output.

    Completion: Outputs agree; the report appears on stderr. Output agreement alone is not evidence of a speed increase.

    Hint: Use the chapter’s commands; do not make internal report identifiers part of expected output.

    3. Debug · Fix a missing caller annotation

    Section titled “3. Debug · Fix a missing caller annotation”

    Check the program below and fix it by enclosing only the reference-creating call in main in a block. Explain why —opt cannot fix it.

    Start with this deliberately broken program.

    class_scope.xen
    #![explc]
    fn append(values: &mut Vec<Int>) { values.push(3); }
    fn main() {
    let mut values = [1, 2];
    append(&mut values);
    println(values);
    }
    Terminal window
    xen check class_scope.xen

    Diagnostic excerpt:

    class_scope.stderr
    passing references requires #![explc]

    Completion: Output is [1, 2, 3]. Check the callee’s declaration and the caller’s scope separately.

    Hint: A callee’s explc setting does not propagate to its caller.

    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.