WHEN Language
A programming language that reimagines program flow through conditional execution and block-based concurrency
# Define variables and blocks first
count = 0
# Concurrent blocks with OS, DE, and FO
os process_data():
when data_ready:
result = process(data)
save(result)
# Main block - execution only, no definitions!
main:
when count < 10:
print(f"Count: {count}")
count = count + 1
when count == 10:
print("Done!")
process_data.start()
exit()
Why WHEN?
Implicit Main Loop
The main block runs continuously until exit() is called. No need for explicit while(true) loops.
Condition-First Design
Uses 'when' statements instead of if/else. Everything is about conditions and reactions.
Block-Based Concurrency
OS (one-shot), DE (declarative), and FO (forever) blocks with parallel execution support.
State Persistence
Built-in save/restore functionality for execution checkpoints. Never lose your program state.
Hot Reload
Live code modification during execution. Change your blocks while they're running!
Python Integration
Seamless interop with Python modules. Use any Python library in your WHEN programs.
See WHEN in Action
# Variables and expressions - defined BEFORE main
name = "World"
count = 0
# Function definitions also come before main
def process_name(n):
print(f"Processing: {n}")
return len(n)
# Main block - execution only!
main:
# WHEN conditions instead of if/else
when count < 5:
print(f"Hello, {name}! Count: {count}")
count = count + 1
when count == 5:
print("Goodbye!")
exit()
# Pattern matching with when
when name is not None:
process_name(name)
# All blocks defined BEFORE main
items = ["apple", "banana", "cherry", "date", "elderberry"]
cpu_usage = 0
memory_low = False
# OS Block - One-shot execution
os fetch_data():
response = api_call()
when response.status == 200:
data = response.json()
process_data.start()
# DE Block - Declarative iterations (fixed count)
de process_items(5):
global items
item_index = 0
when item_index < len(items):
print(f"Processing: {items[item_index]}")
item_index = item_index + 1
# FO Block - Forever loop
fo monitor_system:
when cpu_usage > 80:
alert("High CPU usage!")
when memory_low:
cleanup_memory()
# Parallel execution
parallel de worker_pool(4):
task = get_next_task()
execute(task)
# Main execution block
main:
fetch_data.start()
process_items.start()
monitor_system.start()
worker_pool.start()
exit()
# Imports at the top
import os
# Variable definitions
game_state = {"level": 1, "score": 0}
player = {"health": 100, "position": [0, 0]}
value = 42
folder = "Documents"
data = "test"
# Function definitions
def get_coordinates():
return 10, 20, 30
def reload_config():
print("Config reloaded")
def update_ui():
print("UI updated")
# Block definitions
os update_handler():
# This block can be modified while running!
when file_changed:
reload_config()
update_ui()
# Main execution block - NO DEFINITIONS HERE!
main:
# Save state before risky operation
game_state.save()
when player["health"] <= 0:
# Restore to last checkpoint
game_state.restore()
# Context managers
with open("data.txt", "r") as f:
content = f.read()
process(content)
# Tuple unpacking
x, y, z = get_coordinates()
# F-strings with all variations
print(f"Value: {value}")
print(rf"Raw path: C:\{folder}")
print(f"""Multi-line
string: {data}""")
Quick Start
Install WHEN
pip install when-lang
# or clone from GitHub
git clone https://github.com/PhialsBasement/WHEN-Language/
cd when
python setup.py install
Write Your First Program
# hello.when
main:
print("Hello, WHEN!")
exit()
Run It
when hello.when
# Output: Hello, WHEN!
The WHEN Philosophy
⚡ Everything is a WHEN condition
All branching logic uses 'when' statements. No if/else, no switch/case - just pure conditional reactions.
🔁 Implicit main loop
Code runs continuously by default. The main block keeps executing until explicitly told to stop.
No exceptions, only conditions
Error handling through state checking, not try/catch. Check conditions and react accordingly.