Showing and Running Code

.code, .play and friends

9 October 2026

Ada Example

A whole file

.code code/hello/main.go shows a file as it is:

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}
2

Part of a file

An address picks the lines to show. Lines ending in OMIT are left out:

func fib(n int) int {
    a, b := 0, 1
    for range n {
        a, b = b, a+b
    }
    return a
}

A regular expression alone picks a single line:

func main() {
3

Highlighting

Lines ending in // HLstep are highlighted when the command ends in HLstep:

func fib(n int) int {
    a, b := 0, 1
    for range n {
        a, b = b, a+b
    }
    return a
}

Each word marks its own group of lines. This file also has // HLmain:

func main() {
    for i := range 10 {
        fmt.Print(fib(i), " ")
    }
    fmt.Println()
}
4

Line numbers and editing

func main() {
    for i := range 10 {
        fmt.Print(fib(i), " ")
    }
    fmt.Println()
}

-edit lets the audience change the code on the slide:

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}
5

Running code locally

The rest of these slides run programs with .play. That needs present running on your own machine: pages written by present export, such as these examples on GitHub Pages, only show the code, without a Run button.

To run the programs, start present locally:

go run github.com/some-programs/present@latest serve -doc

Then open http://127.0.0.1:3999 and choose Examples.

6

Running Go

.play runs the program on the machine running present. Click Run, or press shift+enter:

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}
7

Running only part of the source

Only the selected lines are shown, but the whole file is run:

func main() {
    jobs := make(chan int)
    results := make(chan string)

    for w := range 3 {
        go worker(w, jobs, results)
    }

    go func() {
        for i := range 6 {
            jobs <- i
        }
        close(jobs)
    }()

    for range 6 {
        fmt.Println(<-results)
    }
}
8

Several files

A txtar archive holds several files; without a go.mod, one is made.

-- go.mod --
module example/multi
go 1.27
-- main.go --
package main

import (
    "fmt"

    "example/multi/greet"
)

func main() {
    fmt.Println(greet.Hello("present"))
}
-- greet/greet.go --
package greet

func Hello(name string) string {
    return "Hello from another package, " + name + "!"
}
9

Compile errors

Only main is shown, but the errors' line numbers are those of the file, the one in count too:

func main() {
    n := 1
    fmt.Println(greeting(), n+"!")
    fmt.Println(missing)
}
10

Running Python

A .py file runs with python3:

print(list(itertools.islice(primes(), 20)))
11

Running JavaScript and TypeScript

.js files run with node, .ts files too once tsc has checked and compiled them:

for (let i = 1; i <= 15; i++) {
  console.log((i % 3 ? '' : 'Fizz') + (i % 5 ? '' : 'Buzz') || i);
}
function area(s: Shape): number {
  switch (s.kind) {
    case 'circle':
      return Math.PI * s.radius ** 2;
    case 'square':
      return s.side ** 2;
  }
}
12

Other languages

A program starting with #! runs with that interpreter:

#!/bin/sh
# Programs starting with #! run with that interpreter instead of Go.
echo "Running on $(uname -s) as $(whoami)"
date
13
Use the left and right arrow keys or click the left and right edges of the page to navigate between slides.
Press 'S' to show or hide the source of the slide.
(Press 'H', navigate or click this message to hide it.)