Apraxia

From Esolang
Jump to navigation Jump to search

Apraxia is a pattern-based esolang created by User:Yayimhere, after being disappointed by the use of the before mentioned term. In Apraxia, every string of length >1 is valid as code. Apraxia is quite complex compared to some other languages by yayimhere, as it allows recursive functions and variables, as well as null, and a fixed point combinator. All variables in Apraxia are both sub programs/strings, and functions. As such, Apraxia is semi-functionally pure(as all strings are represented by a function).

Etymology

Apraxia's name comes from the name of lisp, as both are speech difficulties. Lisp specifically was chosen as lisp is meme-ed over being full of brackets, or in other words, being very "pattern like".

Syntax

As mentioned before, Apraxia allows all strings of symbols. As such, syntax is very generalized. Note that the last character of the command is special, and always "recognized":

  • For any symbol X that is not recognized: All code between this symbol X and another non recognized symbol Y, is interpreted as the value of X as a variable. Then Y is parsed in the same way, until there are no unrecognized symbols.
  • For any two symbols M & N following each other, that are both recognized: This is function application of the form M(N). Note that for any length of function application, it is nested, so for the symbol set MNW it will be read as M(N(W)).
  • For any single symbol X that is recognized, but is not in a pair is read as a variable value.

Apraxia uses the ISO 8859-1 printable character space.

Semantics

First, there is the last character of the program, which is different from all others. The last character C has the function:

C(XYZ...) -> X(C(YZ...))
C() -> C
C((XY)(YX)) -> X(Y(C((YX)))

This is the before mentioned fixed point combinator, to some extent. As a variable value however, it is just the symbol C. Note that C never is unrecognized, however does end the last variable definition, and is not included in that definition.

For all other variables X, their function is:

X(M) -> C((M(X))(M))
X() -> X

Then, when all variables and functions have been defined, we call the whole program as:

C(Vn-1Vn)

Where each V is one of the variables defined in the program, with Vn being the last defined. Then the whole program is evaluated. When evaluation has completed, the final result is printed.

Do note that the brackets used above are not actually present in the program in any way. As such, ( and ) are valid symbols in the program.

Note that a variable is always expanded to its actual value before anything is applied to it, unless it is being applied as a function. Also, not that this rule applies:

() -> e(the empty string)

Aphasia

Aphasia is a more readable variant of Apraxia, though it is functionally equal, and only compiles to apraxia. Unlike Apraxia, it has an actual "syntax". The program starts with:

x=*

Which sets x to the "fixed point combinator". Then the program is made up of definitions:

name=expr

which sets name to expr. There are two things that make up an expression:

  • function application, written as f(x)
  • and the innermost variable name, which is any variable defined before

then last the program does its call, written as:

[x]

where x can be at max two variables, separated by ; . All variable names must start with a unique character. All definitions are on different lines. There is the special symbol 0, which is the empty string, and during "compiler time" is considered empty. the characters ¡ and ¢ are reserved.

Compiling

We start the compiled Apraxia program as the empty string. Then we change every variable name to only the first character of their name. For every variable definition, add their name, and then their definition, with all brackets removed. For the call itself, if there's two variables called, say x & y, we append:

¡x¢y

and in the case when there's only one we append:

¡x¢

and then we append the name of the variable x=*, and the compiled code is ran.

Example

The program:

c=*
:=0
-=:(:)
;=0
\=-(:)
[\,;]

compiles to:

:-::;\-:¡\¢;c

Examples

Infinite Loop:

XCYCC

as:

XCYCC -> C(XY) -> C(CC) -> C(C(C))

which can also be produced without referencing c:

:-::;:\-:c

or:

:-::*^-':^

or with matching brackets!:

{([(]))}

or, propably the most simple:

: ::*

creating a variable holding C, without referencing it:

:v::c

(note: c should always end the program, in this case).
creating a copying function :(x)=c((x)(x)):

:c

which yes, is just null.