One idea, six shapes

The same program as an editor, a notebook cell, a chat message, an exercise, a slide and a tooltip.

Framework decisions behind it: D49, D60, D65, D66.

One idea, clamp, keeps a number between two bounds. Below it appears as six things a page might need. Each is the same element or the same model, set up differently.

An editor

The whole playground: editor, toolbar and outputs. The JavaScript tab shows the transpiled program.

function clamp(x: number, lo: number, hi: number): number { return Math.min(hi, Math.max(lo, x)); } console.log(clamp(15, 0, 10));

A notebook cell

The editor alone, and its output as a separate pane under it, placed by this page.

function clamp(x: number, lo: number, hi: number): number { return Math.min(hi, Math.max(lo, x)); } console.log(clamp(15, 0, 10));

A chat message

The editor alone inside a message, one button outside it, and the items drawn by the page's own element. The buttons are commandfor buttons; there is no script on this part.

How do I keep a number between 0 and 10?

Clamp it. This runs here:

function clamp(x: number, lo: number, hi: number): number { return Math.min(hi, Math.max(lo, x)); } console.log(clamp(15, 0, 10));

An exercise

Hidden tests judge your code. The program here is OCaml, because its package has the check output; the tests are not shown. Write clamp and press Check.

(* clamp lo hi x keeps x between lo and hi. *) let clamp lo hi x = x

A slide

Slides that run. Focus the slide, then use the left and right arrow keys, or the buttons. The prelude with clamp is folded into each editor.

The slide deck needs JavaScript.

A tooltip

The code is not on screen at all. A hidden playground holds it, and its language server tells each word's type. Press a word.

In , the and the meet in one expression.