Skip to main content

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 https://github.com/PhialsBasement/WHEN-Language.git
cd WHEN-Language

# Run WHEN programs
python when.py program.when

Option 2: Install as Command

# Install globally with pip
pip install -e . 
pip install when-lang

# 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 implementation
  • traffic_light.when - Traffic light simulation
  • restaurant_sim.when - Complex restaurant management system
  • tic_tac_toe.when - Interactive game with AI
  • python_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

when_lang-0.5.0.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

when_lang-0.5.0-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file when_lang-0.5.0.tar.gz.

File metadata

  • Download URL: when_lang-0.5.0.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for when_lang-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a30a573e25670ef345dea7b09aa390d14e1e8bf46ecae5bd8c524f6e6659de9e
MD5 163632e5dbb858ab5ed24e2666faeafe
BLAKE2b-256 141d7fbb0f1fb9920f6bdc39f26d8761e630ab28caa1c28475afb6845e308e00

See more details on using hashes here.

File details

Details for the file when_lang-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: when_lang-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for when_lang-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b561b31c4c4c7d70ec897783659027855dcaded2ef37bbc8df03284e1ea78f9
MD5 f2ba97ee60a4d403ed83e254193cbb01
BLAKE2b-256 7f44a4de49c469bdd61599c2842254af0d30d2b23012aa7e8b60eaa9a9d0aaaa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page