All languages

KnitScript language

Python-like scripting language for V-bed knitting machines: needle sets, carriage-pass directions, and fabric sheets abstract knitout's flat operations, and a Python entry point injects design parameters.

Overview

KnitScript is a domain-specific scripting language for writing V-bed knitting-machine programs. It exposes machine state — carriers, directions, fabric sheets — as scoped language constructs and compiles to knitout, so a design can be parametric without hand-writing needle operations.

Code

// dynamically typed, following Python conventions; statements end with ;
width = 20;                 // int
is_finished = True;         // bool
needle_list = [1, 2, 3, 4]; // list
pattern_dict = {"a": 1};    // dictionary
print f"Knitting {width} stitches";  // f-strings
Python-shaped values and slices; needle-set variables that replace coordinates; functions and with blocks that scope the machine state; then the idiom the paper is about — a gauge of stacked sheets, where layer bookkeeping that knitout leaves to transfers becomes a scope. Every block compiles to Knitout.

Distinctive traits

  • Machine state is lexical: Carrier, Racking, Gauge, and Sheet are scoped variables, not calls into a library.
  • A direction block turns a set of stitches into one carriage pass, sorting them by travel direction instead of source order.
  • reverse and current name a direction relative to the previous pass, so patterns survive being reversed.
  • Built-in needle sets (Loops, Front_Loops, Last_Pass) plus Python slicing select needles declaratively rather than by index arithmetic.
  • Multi-sheet gauges model layered fabric directly, avoiding the transfer sequences a ribbed tube would otherwise need to keep untangled.
  • It is a script, not a schema: Python supplies the parameters and wraps the interpreter for interfaces and generators.

Status

Published at UIST 2023 and released on PyPI as knit-script (MIT), maintained by the Northeastern ACT Lab. Its target is industrial V-bed machines, and it emits knitout rather than vendor data directly.

Sources & references