Powerlist

Powerlist is an esoteric programming language created by User:CodingBat in April 2014. Designed to compute high level arithmetic operations (such as powers or logs) while keeping the syntax minimalistic. It uses a single data structure type, but provides an extensive number of overridable operators.

=Header= Any Powerlist program must have a header which defines the structure of the only variable type allowed. Each header line is a characteristic of the variable, and is enclosed in dollar ($) symbols.

Bit structure line
The first line of the header defines the use of each bit of the type, if the total of bits defined is not a multiple of 8, the computer will assign the minimum byte number needed, making no use of the undefined bits.

Bit usage syntax
The line is made but contatenating the following characters:

Character encoding syntax
The last character of the line defines the character encoding format the program will use. It is also the format the source file will be interpreted as using.

Example: Possible implementation of an ASCII type $SmmmMA$ Example: Possible implementation of classical single-precision floating-point type $SEEMmMmMmMM3$

Special behaviours lines
The other lines of the header override the default behaviour of a give type. This allows things like NaN, INF, -INF values.

Value selection syntax
Each line needs one or more values to be selected, here's the syntax to select a value:

Example: Value with all bit at 1 1: Example: Value with the first bit being either 1 or 0, the ten next bits at 1 then all others at 0 ?1*10*0:

String redefinition syntax
String redefinition lines will affect a special displaying behaviour for the given value that isn't the default. They are written by typing a value then an operator, then a string of characters between quotation marks. The operators are:

Example: A value with all bits at 1 but the first will be printed as "+INF", and a value with all bits at 1 will be printe as "-INF" $01:P"+INF"$ $1:P"-INF"$

Operation redefinition syntax
Operation definition lines will change the effect a given value will result once affected to an arithmetic operation. They take three value selections, the two first separated by the arithmetic operator, the second and the third separated by the equality symbol. Operators availables for redefinition are:

Example: Sets "zero to the power of zero" to return zero (default behaviour returns 1) $0:*0:=0:$ Example: Sets the logarithm of a negative number to return -0 (assuming the variable type's first bit being a signum, and not being floating-point) $1?:\?:=10:$

=Comments= Any text between parenthesis is interpreted as comments and thus ignored.

=Lists= The defined variable type is only used internally by the Powerlist program. The programmer must use another data structure: the list. A list contains values, but unlike a C array, you can't access an arbitrary element of it. You can only access the first and the last item. Lists are the only kind of data structure provided by Powerlist. Lists names can be any characters allowed by the defined character encoding (including digits), with the exeption of,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,   and It is also not allowed to name a list " " (three full stops).

Operators
Here are the operators available to manipulate lists (applied on a example list named List):

Pop operators that feed into another list will automaticly push in it from the fitting side.

Anonymous lists
For faster creation of lists, Powerlist provides a syntax to create anonymous lists. Anonymous lists are deleted once the program stops using it. An anonymous list is created by enclosing it's content between square brackets, and separating each element with a semicolon.

Example: This code creates a list named List and adds to it the values 1, 2, 3, 4, in that order. ~List~ List <+ [1 ; 2 ; 3 ; 4] For anonymous lists the Head Pop and Tail Pop operators behave like the Global Head Pop and the Global Tail Pop respectively, as a syntaxic sugar. So  does the same as

String lists
A special kind of anonymous list allows to create string literals. String lists a created by enclosing the desired string of characters in quotation marks

Example: This code creates a list named List and adds to it the numeric values for each character of the string "List". ~List~ List < "List" This code has the same effect as ~List~ List < [ 76 ; 105 ; 115 ; 116 ]

Literal lists
Powerlist provides built-in lists which provide a single value. These lists have valid names according to the list naming specifications of the language, so they can be freely Created, Deleted, Metacopied and have their operators overriden, though it is frown upon to do so as they provide basic values needed by most programs. The Push and Clone operations has no effect on them, their Length is 0, the Pop and Global Pop operations both return a single instance of their value (though the Repeated Pop operations do provide the requested number of instances), and they are automaticly deleted when the program ends (no need to apply Delete on them). As a syntaxic sugar, the literal list name without any operator is interpreted as a Pop operation in anonymous lists declaration (see above).

Any number literal is interpreted by the program as a litteral list that returns that number. Litteral list are just the number in base 10, with the comma and full stop  both valid as decimal mark.

Example: This code push 42 in a list named List. List < 42

Other literal lists are,  ,  ,  ,  ,  ,   and   (See arithmetic operations for more information)

Operators override
Most Powerlist list operators are overridable to alter the functionnalities of a given list. There is no "class" in Powerlist, each list overrides its operators independantly.

To override an operator, the syntax is to type the operator call, followed by the equal symbol, then the new code for the operator, then close with another equal symbol. Inside the override's scope, a few named lists are provided to access some value otherwise unreachable.

Example: This code overrides the Tail Push operator to push the given value twice. List< = Self<:In Self<In =

The Length Loop operator override requieres a special syntax: List{} = (Code executed before the length check and first loop) {...            (Code executed on loop start, before the code in the brackets at operator call is executed) ...            (Code executed on loop start, after the code in the brackets at operator call is executed and just before the next length check) ...}        (Code executed after the last loop, when the list's length is 0) = =Arithmetic operations= Arithmetic operations in Powerlist are not part of the syntax, instead a built-in list named "Computer" is provided for that purpose. Like other built-in functions, it can be overriden by any way, but this is frown upon because their behaviour is internal and no way is provided to copy their original behaviour.

The Computer list only compute one binary arithmetic operation at a time. When prompted with the Pop operator, the Computer list will take the 3 first values (or the 3 last, depending on which side the Pop operator is on) it holds and process the first and the third through on operation specified by the second. The value for each operation available is not set in the specification, and may change depending on implementation. Powerlist provides literal lists for the operations (, ,  ,  ,  ,  ,   and  ). The  is the only unary operation, the Computer list only processed 2 elements instead of 3 for the others.

The operations available are:

As you can see, Powerlist doesn't implement First level (addition, subtraction) and Second level (multiplication, division) arithmetic operations. Those have been internalized to reduce the language's complexity. Plus, high-level programmers using this language obviously don't need such mundane operations anyway, and even in the rare event of any of those operations being needed, it is well known that the superior operations are able to implement inferior ones. The rest of this chapter will be dedicated to prove that claim.

Addition implementation
$SeeeEEEMMMMMMMMMMMMMMMMMMMMMMMMMMMM$ ~Add~  = [Self^> ; * ; 2]>Computer>Out [Out> ; * ; 2]>Computer>Out [Self^> ; * ; 2]>Computer>Out [Out> ; * ; Out>]>Computer>Out [Out:> ; \ ; 2 ; Out> ; \ ; 2]>Computer+>Out = Display ; * ; -1] Out] Out] Out = [Self^> ; * ; 2]>Computer>Out [Out> ; * ; 2]>Computer>Out [Self^> ; * ; 2]>Computer>Out [-1 ; * ; Computer>Out [Computer>Out [Computer>Out [Out> ; * ; Out>]>Computer>Out [Out:> ; \ ; 2 ; Out> ; \ ; 2]>Computer+>Out = Display = [Self^> ; * ; 2]>Computer>Out [Self^> ; * ; Out>]>Computer>Out [Out> ; \ ; 2]>Computer>Out = Display = [Self^> ; * ; 2]>Computer>Out [-1 ; * ; Self^>]>Computer>Out [Out> ; * ; Out>]>Computer>Out [Out> ; \ ; 2]>Computer>Out = DisplayComputer>Memory [Computer>Memory [Computer>Memory [Computer>Memory ([) ~Loop1~ (Create an empty list, each brainfuck bracket pair needs its own list) Bin< <:Loop1 !Loop1Computer>Memory [2 ; / ; 2]>Computer>Memory [Computer>Memory [<Memory ; \ ; 2]>Computer>Memory [<Memory ; \ ; 2]>Computer>Memory (<) Memory>Memory Bin<Memory Scan>Memory (.) Print<:Memory (>) Memory<Memory (]) Bin<+Loop1 (Empty the list) Bin< <:Loop1 !Loop1<Computer<[<:Memory ; ' ; 0] (If the memory cell is 0, the loop will have 1 element, if not, the loop will be empty) } _Loop1_ (If the list is not empty, restart at the fitting bracket, if not, free the Loop1 list and go on) (end of program) _Memory_ (free the memory list)

=Example programs=

Hello world!
$MMA$ Print<"Hello world!"

cat
$MMA$ Scan { Print<[Scan>] }

Truth machine
$MMA$ ~Out~ Bin < <:Out ! Out < Computer < [0 ; ' ; Scan>] Out { Display<1 } Display<0 _Out_