Whenever
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
Whenever is an esoteric programming language by David Morgan-Mar, with no sense of urgency. The program code is like a to-do list: the interpreter is free to execute statements in any order it chooses. However, a line may contain a clause specifying that it cannot be executed until certain conditions are true. There are no control flow structures or variables.
Syntax
Whenever code must include line-numbers manually typed by the user. So:
1 1#9;
is valid, but:
1#9;
is not.
Commands
line#num/read() - technical variable declaration print(arg) - Self explanatory
Compound statements:
defer(bool) - waits untill the condition in bool is false, which runs the command and remove it from the list (called a to-do list in the specs as shown in External resources) again(bool) - really just doesn't do anything uniqe unless bool is true, as since it's kept in the list forget(bool) - remove the line from the list entirely (and execute it if bool is true)
Built-in functions:
N(n) - returns number of times the line n is in the current to-do list. U(n) - returns the unicode charecter of n
Italic means that the command is deprecated
Examples
Hello, world!
1 print("Hello, world!");
If you want to print "Hello, world!" in two lines for some reason, Do this:
1 print("Hello,");
2 defer(1) print("world!");
Calculator
1 defer(true) 0; 2 defer(true) 0; 3 defer(true) 0; 4 1#read() - 1; 5 defer(4) 2#read() - 1; 6 defer(5) 3#read() - 1; 7 defer(N(2) != 43 || 6) print(N(1) + N(3)); 8 defer(N(2) != 45 || 6) print(N(1) - N(3)); 9 defer(N(2) != 42 || 6) print(N(1) * N(3)); 10 defer(N(2) != 47 || 6) print(N(1) / N(3)); 11 defer(N(2) != 37 || 6) print(N(1) % N(3));
Collatz
1 defer(true) 1; 2 -1; 3 defer(2) 1#read(); 4 defer(3) print(N(1)); 5 defer(4 || N(1)/2*2==N(1) || N(1)==1) 1#(N(1)*2+1), 4, 5; 6 defer(4 || N(1)/2*2<N(1) || N(1)==1) -1#(N(1)/2), 4, 6;
Computational class
It is turing complete, since any Fractran program can be translated into Whenever as follows:
Translating Fractran into Whenever
The first 3 lines:
1 defer(true) 1; 2 defer(true) 2; 3 -1, -2, 1#read();
for the 1st fraction in the form x/y:
4 defer(3 || N(2)!=0 || N(1)==N(1)/y*y) 2; 5 defer(3 || N(2)!=0 || N(1)!=N(1)/y*y) 2#N(1), 1#(N(1)*x/y), -1#N(2), -2#N(2), 5;
for the nth fraction in the form x/y where n > 1:
(2n+2) defer((2n) || N(2)!=(n-1) || N(1)==N(1)/y*y) 2, (2n); (2n+3) defer((2n) || N(2)!=(n-1) || N(1)!=N(1)/y*y) -2#N(2), 2#N(1), 1#(N(1)*x/y), -1#N(2), -2#N(2), (2n), (2n+3);
The last line, where n is the number of fractions in the program:
(2n+4) defer(2n+2) print(N(1));