WHEN Language Interpreter - A unique loop-based programming language
Project description
WHEN Language
A unique loop-based programming language where everything runs in implicit loops with conditional execution.
Features
- Implicit Main Loop: Everything in
main:runs continuously - Block Types:
os name():- One Shot (run once when called)de name(n):- Declarative (run exactly n times)fo name():- Forever (run until stopped)
- Conditional Execution:
when condition:for reactive programming - Block Lifecycle:
.start()and.stop()for managing execution - Python Integration: Import and use Python modules
- Function Support: Define reusable functions with
def
Installation
Option 1: Direct Usage
# Clone or download the WHEN interpreter
git clone <repository>
cd whenloop
# Run WHEN programs
python when.py program.when
Option 2: Install as Command
# Install globally with pip
pip install -e .
# Now use the 'when' command
when program.when
Option 3: Add to PATH (Windows)
# Copy when.bat to a directory in your PATH, or add the whenloop directory to PATH
when program.when
Option 4: Add to PATH (Unix/Linux/macOS)
# Make the script executable and copy to PATH
chmod +x when
cp when /usr/local/bin/
# Or add the whenloop directory to your PATH
when program.when
Usage
when program.when # Run a WHEN program
when -i # Interactive mode (limited)
when --version # Show version
when --help # Show help
Quick Example
# hello.when
count = 0
os setup():
print("Starting up...")
fo counter():
count = count + 1
print("Count:", count)
when count >= 5:
break
main:
when count == 0:
setup()
counter.start()
when count >= 5:
print("Done!")
exit()
Run with: when hello.when
Language Syntax
Variables
x = 10
name = "Alice"
active = 1
Functions
def add(a, b):
return a + b
result = add(5, 3)
Imports
import math
from time import sleep
from random import randint as rand_int
angle = math.sin(math.pi / 4)
sleep(1)
num = rand_int(1, 10)
Blocks
# One-shot execution
os initialize():
print("Setting up...")
# Run exactly 5 times
de heartbeat(5):
print("Beat")
# Run forever until stopped
fo monitor():
check_status()
when error_detected():
break
Main Loop
main:
# Setup (runs once)
when not_started:
initialize()
heartbeat.start()
monitor.start()
not_started = 0
# Conditional logic
when heartbeat_complete():
monitor.stop()
exit()
Advanced Features
Cooperative Scheduling
All blocks run cooperatively in the main loop - no threading complexity.
State Management
Variables persist between loop iterations, enabling stateful reactive programming.
Lifecycle Control
Start and stop execution blocks dynamically based on conditions.
Python Integration
Access the full Python ecosystem within WHEN programs.
Examples
See the included example programs:
clock.when- Simple clock implementationtraffic_light.when- Traffic light simulationrestaurant_sim.when- Complex restaurant management systemtic_tac_toe.when- Interactive game with AIpython_modules_demo.when- Python integration showcase
Contributing
WHEN is a experimental language. Contributions welcome for:
- Language features
- Standard library
- Documentation
- Examples
- Performance improvements
License
MIT License - See LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file when_lang-0.2.0.tar.gz.
File metadata
- Download URL: when_lang-0.2.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cce602fc9725c40fc4503179184f6e1fa1e90abcca1689006a97d56c4812fd30
|
|
| MD5 |
6605b31fa071c000b171c5d439c1617f
|
|
| BLAKE2b-256 |
b275888d2b5342d7e1265a19d50c28c21a626fb715ab3afb7df5f2787cc898d8
|
File details
Details for the file when_lang-0.2.0-py3-none-any.whl.
File metadata
- Download URL: when_lang-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf1acb5672ae10040970dd1715d2b1e995f24b73ec16062e0d194f78685eaef1
|
|
| MD5 |
6e1aa6386d20ea048b53615d7f253e71
|
|
| BLAKE2b-256 |
174fc919366af2c12c35a8559f561ca8befe747842a9405cd130b81ef2f2c82f
|