Yarnball is an esoteric, stack-based programming language where every instruction reads like a crochet pattern.
As of now, the language is in its early stages, with a minimal set of instructions. Currently, it's pretty obvious that what you're reading isn't actually a crochet pattern, but in the future, I would like for a Yarnball program to be indistinguishable from a real crochet pattern.
In Yarnball, operations are expressed using crochet terminology:
- ch (chain): Pushes a number onto the stack.
- pic (picot stitch): Pops a value and prints it as a character.
- yo (yarn over): Pops a value and prints it as a number.
- fo (finish off): Immediately halts program execution.
- subpattern: A reusable sequence of instructions that can be invoked with use (like a function call).
- AND MORE!
Other instructions manipulate the stack (e.g., dc, bob, hdc) or control the flow with loops (rep) and conditionals (if). You can even define reusable stitch patterns with subpattern definitions and invoke them using use.
To run a Yarnball program, use the command line. For example, to run the fib.yarn example, execute:
make
./bin/yarnball examples/fib.yarnIf you prefer an interactive environment, start the REPL by running:
make repl- cmd/main.go - The application entry point that initializes the Yarnball interpreter.
- pkg/evaluator - Implements the evaluator that processes Yarnball instructions.
- pkg/lexer - Responsible for lexing Yarnball source code into tokens.
- pkg/preprocessor/preprocessor.go - Preprocesses Yarnball source code, handling comments and whitespace and other aesthetic features of the language.
- pkg/parser/parser.go - Parses Yarnball source code into an abstract syntax tree (AST).
- docs/specification.md - Provides a detailed description of Yarnball’s instructions and behavior.
- examples/ - Contains sample Yarnball programs.
For a complete list of instructions and their behaviors, see the Yarnball Language Specification.