Code environment execution model

A code environment shows a procedure. Its output is authored; a runnable environment may also be run by the reader, but nothing it prints produces canvas content.

#Execution never authors the canvas

Nothing in a canvas.code environment produces canvas content. By default nothing executes at all; a runnable environment lets the reader run the visible text in a disposable sandbox, and what it prints lands in the environment's console — never on the canvas. No code in an environment produces a plot, feeds a graph, or generates data; the canvas beside it is authored separately.

#No kernels, environments or execution state

An internote therefore carries no kernel, environment, package versions or execution state, and a reader opening a five-year-old internote sees what its author saw. A runnable environment keeps that promise: its sandbox exists for the press of Run and is gone after, and nothing the document shows depends on what one printed. A graph is authored in Chalk and states what its author meant, rather than what a script emitted on the day it last ran.

#Writing the output as a chunk or a comment

A result the reader should see is authored: a comment, or a later chunk stating what an interpreter would print. It is content like the prose and carries the same obligation to be true — quoted from a run rather than predicted, as Checking a document's claims has it.

canvas.code{
    lines{
        z, log_c = np.polyfit(log_area, log_species, 1)
    }
    cue.type{
        lines{
            print(z)   # 0.34
        }
    }(
        in: 1
    )
}(
    language: python
)

#Splicing one source into both halves

Neither half computes the other, so agreement between them is authored. {{ }} splices a shared value into both — a @data column reaches a literal code body as it reaches prose — and a number appearing in both the code and the argument is declared once as a @let constant.

@data#survey:galapagos-plants-1973.csv

scene{
    The areas come from the attached survey.
}[
    canvas.code{
        lines{
            area = np.array([{{#survey.area}}])
        }
    }(
        language: python
    )
]