Simple Pathology: Betterave

Sorry for the missed weeks of friday pathological programming language columns. To be honest, I'm running out of languages. I'm sure there must be more, but my usual sources (dealers?) are running out - so send links!

Anyway, today I'm going to look at a really simple one, which I find fun. It's
not an overly exciting language, but it is a language which is has semantics almost as
trivially simple as [BrainFuck][bf], but which ends up looking almost as much like line-noise as [TECO][teco]. It's called [Betterave][betterave].

[betterave]: http://www.esolangs.org/wiki/Betterave
[teco]: http://scienceblogs.com/goodmath/2006/09/worlds_greatest_pathological_l…
[bf]: http://scienceblogs.com/goodmath/2006/07/gmbm_friday_pathological_progr…

Betterave is a very simple language which is based on prefix operators. (The authors calls them functions, but they're not.) It uses a storage system with 26 variables (one for each letter of the alphabet), and a dictionary of strings indexed by number.
There are 8 kinds of operations in Betterave, and 2 kinds of control flow operators.

Here's the basic list of operators:

1. **Literals**:
* `0-9` - a single digit in Betterave is a zero-parameter operator that returns
the value of the digit. This is the only way to do numeric literals in betterave;
to create a literal like 42, you'd need to use multiple literals and
arithmetic operators: `*76`.
* A literal string written in quotes adds a new string to the dictionary, and
returns the index of the string.
2. **Arithmetic**: `+`,`-`,`*`,`/`,`%` - binary operators that add/subtract/multiply/divide/modulo
the values of the next two expressions.
3. **Comparisons**: `=`, `<`, `>` - compare the value of the next two expressions,
returning 1 if the first is equal/less than/greater than the other.
4. **Input**: "`:`" reads a number from the command-line, and returns it; "`;`" inputs
a string, adds it to the end of the string dictionary, and then returns its index.
5. **Output**: "`.`" prints the value of the following expression as a number; "`,`" prints it as
an ASCII character.
6. **String Operations**:
* *String Append*: The string append commands are "`&`" and "`#`".
They're both binary operators. Their first parameter is the index of a string
to modify, and the second is a number. "`#`" interprets the second parameter
as a number, and the string representation of that number is appended to the
specified string; "`&`" interprets the second character as the ASCII code of
a character, and appends the character to the specified string.
* _Delete character_: "\" takes one parameter, which is the index of a string
to modify. It removes the first character from the string, and then returns
the value of that character.
* _Delete string_: "`_`" takes one parameter which is a string index,
deletes that string from the dictionary, and returns the index of the deleted
string. The index of strings after it are modified by this.
* *Print string*: "`$`" takes one parameter which is the index of a string in
the dictionary, and prints that string.
7. **Variable Operations**: there are 26 variables, a through z. A variable name
in uppercase assigns the value of the next expression to the variable; a variable
name in lowercase returns the value of the variable.

There are two control flow operators in Betterave: loop, and conditional.

* __Loop__: "`[expr1 | expr2]`": this evaluates expr1; then expr2. If expr2 returns
a non-zero value, then it repeats. Loops nest like you'd expect.
* __Conditional__: "`? expr1 expr2 !`". Evaluates expr1. If expr1 evaluates to
non-zero, then it evaluates expr2; otherwise, it skips to the expression following
the next "!". Conditions do not nest: on false, it will just skip to the
next "!", not to a matching "!". So, for example, "`?0 ?=10!.5!.6`" will
output 56: 0 evaluates to zero (false), so it skips to the next "!", after which
it ".5" and then ".6".

So. First example, as usual, is "Hello World".

$"Hello, World!"

Pretty simple. A more interesting version:

"Hello, World!"A+95[,_0A-a1|a]

This stores the string "Hello, World!" in the string dictionary at index 0, and
stores 13 (the number of characters in the string), into variable A. Then it starts a loop. Inside the loop, it removes and outputs the first character of string 0, then subtracts one from A, and repeats the loop if A>0. So it outputs the characters in sequence.

How about a beautifully line-noisy fibonacci series?

AB1[.b,*48TbB+abAt|

Here's how that works:
* Store the value 1 into both A and B. A and B are used to store the two most recent
elements of the fibonacci series.
* Start a loop:
* Output the value of b (the most recently generated fibonacci number).
* Output the character with numeric value 32 (space).
* Store the value of B into T (for temp)
* Set B to A+B
* Set A to t, the stored copy of the old value of b.
* Check if B is smaller than 100. If it is, generate the next number; otherwise,
exit the loop.
* After the loop finished, output the character with numeric value 10 (line feed).

Simple, but horrible.

One more: factorial.

$"Enter a number: "A:B1[B*baA-a1|>a0].b,*25

* Read a number from the keyboard, and store it in A.
* Set B (which will store the result) to 1.
* Start a loop:
* Multiply B by the current value of A
* Subtract one from A
* Repeat as long as a is greater than 0.
* Output B, followed by a carriage return.

*(Note: a couple of typos were corrected in this post.)*

More like this

Todays tidbit of torture is a simple little language called [Leszek][leszek], with an implementation available [here][leszek-impl]. Leszek is based on the idea of *iterative string rewriting*, which is actually a useful and valuable concept. Of course, Leszek takes it to an extreme of insanity…
I've got a real treat for you pathological programming fans! Today, we're going to take a quick look at the worlds most *useful* pathological programming language: TECO. TECO is one of the most influential pieces of software ever written. If, by chance, you've ever heard of a little editor called "…
Today's friday programming language insanity is a tad different. I'm going to look at another twisted stack-based language. I've got a peculiar fondness for these buggers, because back in the day, I was a serious Forth addict. One of the ideas that's actually come up in serious programming…
I thought that it would be fun to stick with the "stack-based" theme of last week's pathological post, but this time, to pick an utterly pointlessly twisted stack based language, but one that would be appreciated by the mascot of one of my fellow ScienceBlogs. Orac, this one's for you! :-) Our…

"and stores 13 (the number of characters in the string), into variable A"

A+95

Isn't 9+5 equal to 14?

Someone:

Damn.
Yep, you're right. Should by 94, not 95.
That's what happens when you do too much editing for format after
pasting it in. I screwed it up. :-)

I'm not sure if this counts as pathalogical, and it's not really fully developed but, LOLCODE is certainly amusing.

By Brian Postow (not verified) on 22 Jun 2007 #permalink

"Hello, World!"A+95[,_0A-a1|A]

Shouldn't that be:

"Hello, World!"A+94[,\0A-a1|a]

Delete char from string, not string from dictionary, and read from (not write to) variable a to see if it's zero.

You might want to reformat the explanation of how the fibonacci example works; the bulleted list is showing up as an asterisk at the beginning of every sentence, with no line breaks. At least, that's how it looks for me.

Eh, that's my language! Wow... I'm very surprised it ended somewhere else than on the Esolangs wiki.

As it is a work in progress, some errors and bugs are still present. I'll correct them as soon as I can.

Please understand that English isn't my mother tongue. I do my best to prevent inconsistencies when I write.

Don't hesitate to contact me if you have comments / suggestions / criticisms to share!

By Alexandre Boily (not verified) on 24 Jun 2007 #permalink

Tegumai,

The caution at the end of the article should be taken seriously.

Additionally, if you're allergic to ragweed, echinacea may make you feel worse than having a cold would, as a friend of mine found out the hard way. :( I put it in the "use with caution" category at best -- I'd rather be dumping tons of oregano into my system than echinacea, personally.