Next: 2. Onyx Language Reference Up: 1. Onyx Language Tutorial Previous: 1.12 Optimization Contents Index

# 1.13 Debugging

Onyx does not have an integrated interactive debugger per se, because the introspective power of Onyx is adequate for almost all debugging purposes. In cases where it is impractical to interactively debug an application via the main thread, it is possible to launch a thread that listens for connections on a socket (or a fifo pair) and provides an interactive session.

Following is a contrived example of debugging some bad code, interleaved with explanations. The intention is to calculate .

    onyx:0> 1 5L add
    Error $undefined
    ostack: (1)
    dstack: (-dict- -dict- -dict- -dict-)
    estack/istack trace (0..2):
    0:      5L
    1:      -file-
    2:      --start--
    onyx:2> pstack
    5L
    1

`5L` is not a number, nor is it defined in dstack. Try replacing `5L` with `$five`.

    onyx:2> pop $five resume
    Error $typecheck
    ostack: (1 $five)
    dstack: (-dict- -dict- -dict- -dict-)
    estack/istack trace (0..2):
    0:      --add--
    1:      -file-
    2:      --start--
    onyx:3> pstack
    --add--
    $five
    1

`$five` is a literal name, so no errors occur directly due to scanning it. However, the add operator expects two numbers, and `$five` is not a number. Replace it with `5` and evaluate the operator.

    onyx:3> nip 5 exch eval
    onyx:1> pstack
    6

The result is as desired. However, we forgot to resume after the last error.

    onyx:1> estack 1 sprint
    (--start-- -file- --add-- --ifelse-- --eval-- -array- -file- --estack--)
    onyx:1> resume

Now the estack contents should be back to normal.

    onyx:1> estack 1 sprint
    (--start-- -file- --estack--)
    onyx:1>

The above example only demonstrates the flavor of typical interactive debugging, but there is no magic involved in debugging, so your debugging ability should improve automatically as you gain an improved understanding of Onyx.

Next: 2. Onyx Language Reference Up: 1. Onyx Language Tutorial Previous: 1.12 Optimization Contents Index