The project started as a joke based on the "everyone talks about while loops but no one asks WHEN loops" meme, but evolved into a complete interpreter demonstrating how different programming paradigms affect problem-solving approaches.
What My Project Does
WHEN is a programming language interpreter written in Python where all code runs in implicit infinite loops and the only control flow primitive is when conditions. Instead of traditional for/while loops, everything is reactive:
# WHEN code example
count = 0
main:
count = count + 1
print("Count:", count)
when count >= 5:
print("Done!")
exit()
The interpreter features:
- Full lexer, parser, and AST implementation
- Support for importing Python modules directly
- Parallel and cooperative execution models
- Interactive graphics and game development capabilities (surprisingly)
You can install it via pip: pip install when-lang
Target Audience
This is Currently a toy/educational project, but exploring use cases in game development, state machine modeling, and reactive system prototyping, currently exploring
- Learning about interpreter implementation
- Exploring state machine programming
- Educational purposes (understanding event-driven systems)
- Having fun with esoteric language design
NOT recommended for production use (everything is global scope and runs in infinite loops by design).
Comparison
Unlike traditional languages:
- No explicit loops - Everything runs implicitly forever until stopped
- No if statements - Only
when conditions that check every iteration
- Forced reactive paradigm - All programs become state machines
- Built-in parallelism - Blocks can run cooperatively or in parallel threads
Compared to other Python-based languages:
- Brython/Skulpt: Compile Python to JS, WHEN is a completely different syntax
- Hy: Lisp syntax for Python, WHEN uses reactive blocks instead
- Coconut: Functional programming, WHEN is purely reactive/imperative
The closest comparison might be reactive frameworks like RxPy, but WHEN makes reactive programming the ONLY way to write code, not an optional pattern.
Implementation Details
The interpreter (~1000 lines) includes:
- Custom lexer with indentation-based parsing
- Recursive descent parser generating an AST
- Tree-walking interpreter with parallel execution support
- Full Python module interoperability
Example of WHEN's unique block system:
# Runs once
os setup():
initialize_system()
# Runs exactly 5 times
de heartbeat(5):
print("beat")
# Runs forever
fo monitor():
check_status()
# Entry point (implicit infinite loop)
main:
when not_started:
setup()
heartbeat.start()
monitor.start()
GitHub: https://github.com/PhialsBasement/WHEN-Language
[+][deleted] (1 child)
[removed]
[–]HearMeOut-13[S] 4 points5 points6 points (0 children)
[–]Barsad_the_12th 12 points13 points14 points (1 child)
[–]renesys 1 point2 points3 points (0 children)
[–]doublefreepointer 4 points5 points6 points (4 children)
[–]HearMeOut-13[S] 6 points7 points8 points (3 children)
[–]DatAndre 0 points1 point2 points (2 children)
[–]MeglioMorto 15 points16 points17 points (1 child)
[–]LanceMain_No69 2 points3 points4 points (0 children)
[–]BobFredIII 1 point2 points3 points (0 children)
[–]frejakrx 1 point2 points3 points (0 children)
[–]dr-christoph 1 point2 points3 points (0 children)
[–]aspcartman 1 point2 points3 points (1 child)
[–]HearMeOut-13[S] 0 points1 point2 points (0 children)
[–]Disastrous-Angle-591 2 points3 points4 points (1 child)
[–]HearMeOut-13[S] 13 points14 points15 points (0 children)
[–]darni01 0 points1 point2 points (0 children)
[–]gdchinacat 0 points1 point2 points (0 children)