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
Carrier = c1; // machine state: the active carrier
in Leftward direction:{ // one carriage pass, one direction
tuck Front_Needles[0:width:2]; // even needles: a Python-style slice
knit Loops; // a built-in set: needles holding loops
}
xfer Front_Loops 2 to Right to Back bed; // offset transfer
drop Front_Needles[0:5];
def alt_tuck_cast_on(width = 10):{ // default argument, as in Python
in Leftward direction:{
tuck Front_Needles[0:width:2];
}
in reverse direction:{ // opposite of the last directed pass
tuck Front_Needles[1:width:2];
}
}
with Carrier as c1:{ // carrier state is scoped
alt_tuck_cast_on(12); // call it
}
with Carrier as c1, Gauge as 2:{ // two fabric sheets, layered for free
with Sheet as s0:{ // rib on the front of the tube
in Leftward direction:{ knit Front_Needles[0:width:2]; }
}
with Sheet as s1:{ // falls behind s0 by default
in reverse direction:{ knit Back_Needles[1:width:2]; }
}
for _ in range(height):{
with Sheet as s0:{ in reverse direction:{ knit Loops; } }
with Sheet as s1:{ in reverse direction:{ knit Loops; } }
}
}
cut c1;
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, andSheetare 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.
reverseandcurrentname 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
- Official sitemhofmann-khoury.github.io
- KnitScript — language reference (Northeastern ACT Lab)mhofmann-khoury.github.io
- KnitScript — machine operations guidemhofmann-khoury.github.io
- knit_script repository (mhofmann-Khoury/knit_script, MIT)github.com
- knit-script on PyPI — V-bed knitting machine languagepypi.org
- KnitScript: A Domain-Specific Scripting Language for Advanced Machine Knitting (UIST 2023)make4all.org