Unassignable

From Esolang
Jump to: navigation, search
The title of this article is incorrect because of technical limitations. The correct title is :≠.

:≠ is a reversible object-oriented esoteric programming language created by User:ais523 in 2006. It was created as an easier way to write ABCDXYZ and BackFlip programs (although there is not yet a compiler into either language); ABCDXYZ programs are trivial to translate into it. The language's name is pronounced 'Unassignable'; it is a reference to the most frequently used operation impossible in a reversible programming language.

Syntax

A :≠ program consists of a declarations section and a definitions section; the declarations section specifies the types and initial values of each object in the program, and the definitions section specifies their events. (The methods are predetermined for each object).

The declarations section starts with the line

declarations

followed by a list of object declarations, which can take one of the following forms:

integer identifier(maximum)=initial value;
function identifier=initial value;
ABCD identifier=initial value;

The initial value must be a legal value for the object type (integer, function or ABCD); see Data types. Identifiers start with a letter, followed by letters, underscores, and digits. They are case-sensitive and limited to 40 characters long. Identifiers starting 'una' are reserved for use by an implementation and shouldn't be used in a program.

The definitions section starts with the line

definitions

followed by a list of object definitions, which take the following form:

objectname
{
  eventname1
  {
    commandlist
  }
  eventname2
  {
    commandlist
  }
}

There can be any number of events, from 0 (which is pointless) up to the number of events that the object type has. Any events that the object type has, but are not specified in the definition, are assumed to be NOPs.

A command list is a list of commands in one of the following forms:

objectname->method;
objectname->method(argument);

Arguments are always constants.

Data types

There are three data types in :≠:

  • The integer. It has a minimum value of 0, and a user-specified maximum value (which must be one less than a power of 2, and no greater than 4294967295). An integer with a maximum of 0 is not allowed (zero-bit integers are not supported in the current version of :≠). It has three methods (increment, decrement, and loop), and three events (overflow, underflow, and iterate).
  • The function. It has only two possible values: activated and deactivated, three methods (activate, deactivate, and call), and one event (run).
  • The ABCD. This is the data type described in ABCDXYZ; it has four possible values (A, B, C, and D), three methods (X, Y, and Z), and one event (event).

There is also the predefined object io, which has its own data type (which is unnamed as a variable of that type cannot be declared), and one method (output). (This is subject to change in later versions of :≠.)

Methods and events

The semantics of each method are as follows:

  • increment(X): Adds X to the integer it is called on (X must be a power of 2). If the integer overflows, its overflow event is called, and its value wraps round (e.g. maximum + 1 = 0).
  • decrement(X): Subtracts X from the integer it is called on (X must be a power of 2). If the integer underflows, its underflow event is called, and its value wraps round (e.g. 0 - 1 = maximum).
  • loop: Calls the integer's iterate event a number of times equal to the integer's current value.
  • activate: Sets a function's value to activated. If the function is already activated, this leads to undefined behaviour.
  • deactivate: Sets a function's value to deactivated. If the function is already deactivated, this leads to undefined behaviour.
  • call: If the function is activated, fires its run event; if it is deactivated, does nothing.
  • X,Y,Z: These have the same semantics as in ABCDXYZ; they only apply to ABCD objects.
  • output(X): X must be a digit or N. If X is a digit, it is written to standard output; if X is N, a newline is written to standard output. Anything else as an argument is undefined. (This method must not be used if the program is to be compiled into unextended BackFlip.)

Program execution

At the start of the program, the command

main->call;

is executed by the calling process. (There must be a function called main; the user is advised to define it to start activated, otherwise their program will do nothing).

Just as in ABCDXYZ, recursion is completely banned. If an event of an object is anywhere in the call stack, no methods of that object can be called (even ones which won't lead to further events, such as deactivate or Z).

Example

declarations 

integer mainloop(7)=5;
integer count(7)=0;
function main=activated;

definitions 

main
{
  run
  {
    mainloop->loop;
  }
} 

mainloop
{
  iterate
  {
    count->increment(1);
    count->loop;
    io->output(N);
  }
}

count
{
  iterate
  {
    io->output(1);
  }
}

This program outputs:

1
11
111
1111
11111

Computational class

:≠ has finite data storage and is reversible, and so must terminate. It cannot be Turing-complete, but can be compiled into ABCDXYZ (the proof).

See also