Possibilities
Code
#be firm
evermore: TIMEORMASS = 150;
possibility: subject = `my|(y?our)`;
possibility: object = `w(eigh|ai)t`;
retell (upto: 6) {
sometimes (schrodinger()) {
tellme(subject, object, "of", TIMEORMASS);
} othertimes {
tellme("and");
}
}
Console
Run 1:
and
your wait of 150
our wait of 150
and
Run 2:
my wait of 150
and
and
my weight of 150
our wait of 150
your wait of 150
Run 3:
your wait of 150
my wait of 150
your weight of 150
and
Explanation
This program demonstrates a range of features in the language.
After the #be directive, the first line defines an evermore, or a constant, named TIMEORMASS, as 150.
evermore: TIMEORMASS = 150;
When TIMEORMASS is referred to from now on, it will always have the value 150.
Then, two possibilitys are defined. The first, subject, is given the value my|(y?our).
possibility: subject = `my|(y?our)`;
This is a regular expression that can be broken down like this:
- The parentheses
()group the tokens inside to be considered in context:(y?our). - The pipe
|operator matches either expression on either side:myor(y?our). - The question mark
?operator matches 0 or 1 of the previous token:yourorour. - All together, the expression matches:
my,your, andour.
The second possibility, object, is given the value w(eigh|ai)t.
possibility: object = "w(eigh|ai)t";
This regular expression can be broken down like this:
- The parentheses
()group the tokens inside:(eigh|ai). - The pipe
|operator matches either expression on either side:eighorai. - All together, the expression matches:
weightorwait.
As possibilitys that hold regular expressions as values, these can result in different results under different conditions, which are demonstrated in the following code block.
The retell code block evokes the experience of retelling a story—it comes out slightly differently each time. Modifying it with (upto: 6) sets it to retell any number of times, up to 6 times.
retell (upto: 6) {
// statements here
}
The actual statements to be carried out within the retelling are given in the sometimes-othertimes blocks. Analogous to if-else patterns in other languages, sometimes-othertimes is a pattern that will execute the sometimes code block if the condition is true; otherwise, it will execute the othertimes code block. The condition here is schrodinger(), which is a function that, like Schrödinger’s cat, is simultaneously both true and false—but will give you just one of those values when you run it.
sometimes (schrodinger()) {
// some statements
} othertimes {
// other statements
}
Within those code blocks, tellme() is analogous to print() or console.log() in other languages: it will print a given value to the console. The first tellme() prints a string of concatenated values: the possibility named subject, the possibility named object, the string “of”, and the evermore named TIMEORMASS. Every time this is run, the possibilitys will return a string that matches their regular expressions—remember that regular expressions can match multiple strings!
tellme(subject, object, "of", TIMEORMASS);
All together, this program prints up 6 lines that combine, in different ways, the possibilitys “my”, “your”, “our”, “weight”, “wait”; the word “of”; the evermore value 150; and the word “and”. The three runs show the different results that can occur.