Betterave

From Esolang
Jump to: navigation, search

Betterave is a functional programming language created by User:Boily in 2007.

Syntax[edit]

In the spirit of Brainfuck, False and Befunge, Betterave's commands are assigned to single characters. But, unlike these three languages, it is not tape- nor stack-based. Instead, programs are written as expressions. Like Scheme, it has a prefix notation, but unlike Scheme, there are no parentheses; each operator knows how many arguments must follow it. Thus, for example, the parameters of an addition come after the "+" symbol.

Most things in Betterave are considered to be function calls, even numbers. When the interpreter encounters a digit, its value is immediately returned to the preceding command for further evaluation. This means that to obtain numbers bigger than 9, you will have to use mathematic operations. If you want to use a number like 42, a possible solution may be:

*67

Or, if you feel more verbose,

-**2558

Which produces the same result.

Structure[edit]

Control flow is achieved with two means. There is the

[ xxx | yyy ]

construct. When encountered, the "[" does nothing. It has the same purpose as a label. The "|" (pipe) evaluates the "yyy" function. If it is true, the interpreter jumps to the corresponding "[", else it jumps to the following "]". Also, there is the pair:

? xxx yyy !

If "xxx" evaluates to a non-zero value, then yyy is evaluated. Else, the interpreter jumps to the next "!". These commands somewhat work as a "normal" if-statement. Because of the syntax, if you need to express a thing such as "IF a AND b THEN do something", you will have to write:

? aaa ? bbb yyy !

It is possible to nest "bracket-pipe-bracket" blocks, but "interro-bang" blocks do not have this property.

Strings[edit]

Betterave's strings are contained in a list. Each string is assigned an index, beginning at zero and counting upwards. To create a new string you may ask one for input by the user with the

;

command, or you may specify one with

" content of string "

To append a character to an existing string, use

& xxx yyy

where "xxx" is the index of the string and "yyy" is the character to append. "#", instead of appending a character, adds a number.

The "_" command deletes a string. This shifts the index of the strings that had a higher index than the one deleted.

List of commands[edit]

Every character not in this list is ignored (this includes whitespace).

Command Description
~ ... ~ Comments are surrounded by tildes.
0-9 Digits (0 - 9) return the corresponding value.
+, -, *, /, % Base mathematical functions. Return the {sum, difference, product, quotient, modulo} of the next two functions.
=, <, > Comparison functions. Return 1 if true, 0 if false, by comparing the next two functions.
" ... " Add a string to the string list. Return the index of the string.
[ ... | ,,, ] If ,,, evaluates to a non-zero value, go back to the corresponding [, else jump to the next ].
? ... ,,, ! If ... evaluates to a non-zero value, continue parsing, else jump to the next !.
: Input an integer and return its value.
; Input a string, add it to the string list, return the index of the string.
. Print the value of the next function and return it.
, Print the value of the next function as an ASCII character and return it.
& Append to the string designed by the index returned by the next function the ASCII character returned by the function after.
# Same as & but appends a number.
\ Return the ASCII code of the first character of a string and delete it from the string.
_ Delete a string and return the index of the string deleted
$ Print the string designed by the index returned by the next function.
A-Z Set a variable (represented by a single letter).
a-z Get the value of the variable.

Examples[edit]

Hello, World! program:

$"Hello, World!"

This prints all the Fibonacci numbers smaller than 100:

AB1[.b,*48TbB+abAt|<b**455],*25

Not quite grammatically correct 99 bottles of beer:

B*+569" bottles of beer on the wall,
"" bottles of beer.
Take one down, pass it around,
"" bottles of beer on the wall.

"[.b$0.b$1.B-b1$2|>b0]

External resources[edit]