WHEN Programming Language Documentation

Overview

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.

Core Philosophy

  • No traditional loops: Use de (declarative) blocks instead of for/while
  • Conditional execution: All control flow uses when statements
  • Explicit concurrency: Parallel execution with parallel keyword
  • Block-based architecture: Code organized into execution blocks
  • State persistence: Variables maintain state across block executions

Language Features

Block Types

Block 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

Control Flow

  • when condition: - Conditional execution
  • break - Exit current block
  • continue - Skip to next iteration
  • exit() - Terminate program
  • return value - Return from function

Block Operations

  • block_name.start() - Start a block
  • block_name.stop() - Stop a block
  • block_name.save() - Save current state
  • block_name.savestop() - Save and stop
  • block_name.startsave() - Start from saved state
  • block_name.discard() - Discard saved state

Quick Start

# 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()

Installation

# 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

Key Concepts

1. Conditional Execution

Everything uses when instead of if:

when x > 10:
    print("Large number")
when x <= 10:
    print("Small number")

2. Block-Based Concurrency

# 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}")

3. State Management

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

Next Steps