Indent
Indent is an esolang by User:PythonshellDebugwindow.
I/O
There is no input, and the only thing output by a program is the main
function's final return value (or 0).
Program execution
The main
function is called with the passed Command Line Args as an IntArray.
Functions
All functions return Ints (default return value/value returned if non-Int is attempted to be returned is 0), but this could be used with Array indexing to access elements of an Array of any type. The last evaluated statement in a function is its return value. All arguments to a function must also be Ints, but they could also be used with Array indexing. The passed arguments (number of args >= 1, no args -> args = [0]) is stored in an IntArray called arg
. To define a nop function (no body, returns 0):
nop
A bitwise AND function:
bwAnd arg.0 & arg.1
A (non-bitwise) not function using a conditional:
not arg.0 = !(arg.0), !(arg.0)
To call a function:
f = arg
Multiple args:
f = [arg1, arg2, arg3]
Chained calls:
f1 = (f2 = args)
No args:
noArgs = 0
Any non-passed args/non-Int args will be replaced with 0, and any extra args are ignored.
Variables
- This section uses Int literals in its examples for demonstrational purposes. There are no Int literals in Indent.
Variables are strongly typed. The type of their initial value will be their type for the rest of the program. To initialize the variable myVar
to Int and set it to 123:
myVar <123>
To change it:
myVar <456>
But you can't assign it a different type, as any attempts to do so will fail silently:
main myVar <123> myVar <1, 2, 3> myVar
will output 123
, as assigning a value of type IntArray to a variable declared as an Int will fail and return -1
.
Scope
Variables declared at the top of the program can be used in all functions; variables declared in a specific function can be used only in that function; variables declared between functions are invalid and are ignored.
Datatypes
Datatypes are Int, IntArray, Function, FunctionArray, NDIntArray, and NDFunctionArray. The term Array can be used to generically refer to any Array type, and the term Any can be used to generically refer to any type. Ints are signed.
Int literals
There are no Int literals; you can use the Command Line Args to use Ints in your program, e.g. arg.0 & !arg.0
is always the Int 0, and using the not function described, you can turn it into the Int 1; nop functions always return 0 as well.
Operators
Operator | JavaScript equivalent |
---|---|
. |
LHS[RHS] where LHS is Array and RHS is Int
|
& |
LHS & RHS where LHS is Int and RHS is Int
|
| |
LHS | RHS where LHS is Int and RHS is Int
|
! |
(RHS ? 0 : 1) where RHS is Int; unary operator, no LHS
|
= |
if(LHS) RHS; where LHS is Int and RHS is Function or a literal piece of code
|
= |
if(LHS) RHS[0]; else RHS[1]; where LHS is Int and RHS is Array or Array of literal pieces of code
|
= |
LHS(RHS) where LHS is Function and RHS is Int or IntArray
|
, |
Array(LHS) + [RHS] where LHS is Any and RHS is typeof LHS or typeof the items in LHS
|
[] |
[...MID] where MID is IntArray
|
() |
(MID) (grouping) ((1, 2, 3) = invalid syntax, use [] instead)
|
<> |
(LHS) = RHS where LHS is an identifier and RHS is Any; no prior initialization, e.g. var x = y , needed; if assignment is successful, the new value of LHS will be returned, else -1 will be returned
|
Examples
Truth-machine (prints nothing for input 1, but loops infinitely), treats all nonzero inputs as 1:
main arg.0 & arg.0 = main(arg.0), arg.0
XOR function (args: two Ints to XOR):
xor (arg.0 | arg.1) & !(arg.0 & arg.1)
While function (args: the Nth function in the condfuncs
FunctionArray and the Nth function in the bodyfuncs
FunctionArray) that returns 0:
condfuncs <list, of, functions> bodyfuncs <list, of, functions> while (condfuncs.(arg.0) = 0) = [bodyfuncs.(arg.1), while = [arg.0, arg.1]]
If function (args: an Int for the condition and the Nth function in the bodyfuncs
FunctionArray):
bodyfuncs <list, of, functions> if arg.0 = (bodyfuncs.(arg.1) = (arg.0 & !arg.0))
Nop function w/ no body (this example will print 0):
nop main nop
Resources
- Undefined identifiers are treated as 0, and undefined array indexes are treated as 0 for IntArrays, nop functions for FunctionArrays, and the empty array of appropriate type for multidimensional arrays
- Regex for identifiers:
[A-Za-z0-9_]+