Whenever

Introduction

Design Principles

Program code lines will always be executed, eventually (unless we decide we don't want them to be), but the order in which they are executed need not bear any resemblance to the order in which they are specified.

Variables? We don't even have flow control, we don't need no steenking variables!

Data structures? You have got to be kidding.

Language Concepts

Line Numbers

Program Execution

Syntax Elements

Strings

Operators and Expressions

+, -, *, /, &&, ||, !

Arithmetic and logical expressions are constructed as usual. Any floating point arithmetic expression in an integer context is treated as if truncated (rounded towards zero). Numbers and booleans in a string context are converted to strings. The plus sign doubles as a string concatenation operator. Increment, decrement and assignment operators do not exist, since there are no variables for them to operate on.

Line Numbers as Booleans

Simple Statements

line-number statement;

Line Numbers

line-number#number-of-times-to-add/remove

1 4,5#3,-6;

Input

1 2#read();

Output

1 print("Hi there");

Compound Statements

defer

line-number defer (boolean) statement;

1 defer (2) 3;

again

line-number again (boolean) statement;

1 again (2) 3;

forget (deprecated)

line-number forget (boolean) statement;

1 forget (2) 3;

1 defer (4 && !2) 3;

4 defer (2) -1;

Combinations of compound statements

Built-in Functions

N()

U()

Sample Programs

Hello World

1 print("Hello world!");

Endless Loop

1 1;

Memory Hog

1 1#9;

99 Bottles of Beer

1 defer (4 || N(1)<N(2) || N(2)<N(3)) print(N(1)+" bottles of beer on the wall, "+N(1)+" bottles of beer,");

2 defer (4 || N(1)==N(2)) print("Take one down and pass it around,");

3 defer (4 || N(2)==N(3)) print(N(1)+" bottles of beer on the wall.");

4 1#98,2#98,3#98;

Fibonacci Numbers

1 again (1) defer (3 || N(1)<=N(2) || N(7)>99) 2#N(1),3,7;

2 again (2) defer (3 || N(2)<=N(1) || N(7)>99) 1#N(2),3,7;

3 defer (5) print(N(1)+N(2));

4 defer (5) print("1");

5 4,-3,7;

6 defer (4) 3;

7 7;

8 defer (N(7)<100) -1#N(1),-2#N(2),-7#100,-3;

9 defer (3 || 6) 1,3;

Resources

Whenever interpreter written in Java.

Download the jar file, extract the classes and sample program (fib.txt). Type java Whenever fib.txt to generate the first 100 fibonacci numbers. This program starts fast but as it accumulates thousands of deferred lines it takes longer and longer to execute the print statement... It probably eventually exceeds the JVM MAXINT but I haven't had the patience to let it run that long.

NB: This interpreter does not yet support the U() function, or unary logical not operator (!).

Whenever.jar (8695 bytes)

Whenever_source.zip (5777 bytes)

Download the jar file, extract the classes and sample program (fib.txt). Type to generate the first 100 fibonacci numbers. This program starts fast but as it accumulates thousands of deferred lines it takes longer and longer to execute the print statement... It probably eventually exceeds the JVM MAXINT but I haven't had the patience to let it run that long. NB: This interpreter does not yet support the U() function, or unary logical not operator (!). Whenever.jar (8695 bytes) Whenever_source.zip (5777 bytes) Whenever implemented using JavaScript functions, by Sarah GP.

The Whenever syntax implemented in JavaScript, by Fredrik H.

Whenever on the net