Iexp

From Esolang
Jump to navigation Jump to search
Iexp
Paradigm(s) declarative
Designed by User:Fergusq
Appeared in 2015
Dimensions one-dimensional
Computational class Unknown
Major implementations Unimplemented
Influenced by LISP
File extension(s) .iex, .iexp

Iexp or IEXP (pronounced /'jeksp/) is an infix expression based programming language.

Overview

The only datatype in Iexp is a iex, an infix expression. There are two kind of iexes: operative and non-operative. An operative iex consists of two operands and an operator, placed in the middle. A non-operative iex is a single operator, in other words, its operands are both null pointers.

The syntax is very simple. The input file must have a single line of code, a space-separated list of operators and non-operative operators. No parentheses are allowed, they are unnecessary. Iexp has an incredible and innovative syntax which replaces all need for parentheses, called the dot notation. The precedence of an operator is determinated from the number of dots before it. More dots, higher precedence.

a op1 b op2 c = (a op1 b) op2 c
a op1 b ·op2 c = a op1 (b op2 c)

The Iexp interpreter, after parsing, starts evaluating iexes following the precedence. If, however, a iex is starred (has a star before the operator after the dots), it is not evaluated. The interpreter instead returns a starless copy of the starred iex. It is not necessary to star non-operative expressions. A lone star signifies an empty, zero-length iex.

p + q          => pq
q *+ p         => p + q
q *+ p *+ r    => p + q *+ r
: left p ·*+ q => p

A colon is typically used if the left operand is ignored. left is a iexo (see below) which returns the left operand of its right operand.

Iexo reference

A list of Iexp operators (iexos):

Iexo Description
a + b Concatenates two non-operative expressions.
a - b Removes the first occurance of non-operative iex b from non-operative iex a. If a does not contain b, an error is raised.
a or b If a is a zero-length iex, evaluates and returns the value of b. Otherwise returns a.
a then b If a is not a zero-length iex, evaluates and returns the value of b. Otherwise returns a.
a return b Returns always b.
: left b Returns the left operand of the operative iex b.
: right b Returns the right operand of the operative iex b.
a and b Returns a new operative iex with a as the left operand, b as the right and "and" as the operator.
a copy b Returns a new operative iex which has the left operand of a as the left operand, the right of a as the right and non-operative b as the operator.
a in b Expects a to be an operative iex. The operator of a should be "is". The left operand of a should be a non-operative iex. An error is raised if the aforesaid rules are not followed. Creates a new interpretation context, where a new iexo, possibly overwriting an older iexo, is introduced with the left operand of a as the name and the right operand of a as the body, and evaluates b in that interpretation context. If the newly introduced iexo is being called, creates again a new context and introduces two new iexos, "1" and "2" which correspond to the values of the operands and evaluates the body in that context. The iexo returns the value of its body. Recursive calls are permitted.
: 1 : (Only in is-context.) Returns the value of the left operand.
: 2 : (Only in is-context.) Returns the value of the right operand.

Examples

Hello world

Hello world!

Because it is impossible to create normal spaces in Iexp, the above example uses a non-breaking space.

Fibonacci sequence

fib ·*is : ····2 : ···then : ·······2 : ······- . ·····then * ·······fib : ·········2 : ········- . ······*+ * ·······fib : ·········2 : ········- .. ····*or . ··or * in * ·*fib .....