WHEN is a Python-based programming language designed around conditional execution and explicit concurrency. Instead of traditional loops, WHEN uses declarative blocks that execute based on conditions and iteration counts.
de
(declarative) blocks instead of for
/while
when
statementsparallel
keywordBlock Type | Purpose | Execution |
---|---|---|
main: |
Entry point | Runs continuously |
fo name(): |
Forever block | Runs until stopped |
de name(N): |
Declarative block | Runs exactly N iterations |
os name(): |
One-shot block | Runs once when called |
parallel fo/de |
Parallel execution | Runs in separate thread |
when condition:
- Conditional executionbreak
- Exit current blockcontinue
- Skip to next iterationexit()
- Terminate programreturn value
- Return from functionblock_name.start()
- Start a blockblock_name.stop()
- Stop a blockblock_name.save()
- Save current stateblock_name.savestop()
- Save and stopblock_name.startsave()
- Start from saved stateblock_name.discard()
- Discard saved state# Simple WHEN program
counter = 0
de count_to_five(5):
counter = counter + 1
print(f"Count: {counter}")
main:
count_to_five.start()
when counter >= 5:
print("Done!")
exit()
# Clone repository
git clone <repository-url>
cd when-language
# Run WHEN programs
python when.py program.when
# Interactive mode
python when.py -i
# Hot reload for development
python when.py --hot-reload program.when
Everything uses when
instead of if
:
when x > 10:
print("Large number")
when x <= 10:
print("Small number")
# Cooperative execution (main thread)
fo background_task():
print("Background work")
sleep(1)
# Parallel execution (separate thread)
parallel fo heavy_computation():
result = calculate_fibonacci(30)
print(f"Result: {result}")
progress = 0
de worker(10):
progress = progress + 1
when progress == 5:
worker.save() # Save checkpoint
when some_error_condition:
worker.savestop() # Save and stop
worker.startsave() # Resume from save