GnomeLang

From Esolang
Jump to navigation Jump to search
GnomeLang
Paradigm(s) Concurrent,Imperative
Designed by Thomas
Appeared in 2025
Memory system Cell-based
Computational class Turing complete
Reference implementation Unimplemented
File extension(s) .dcre

GnomeLang is an esoteric programming language created by Thomas, that models computation as gnomes interacting with bidirectional infinite tapes (gardens). It combines Turing machines and multi-agent systems.

Terminology

Gnomes: Computational agents that move, read, write, construct new gnomes, and die, each gnome has memory, as a stack of integers.

Gardens: Doubly infinite tapes (like Turing machine tapes), whose language is '0', '1', '_' (blank).

Decrees: Programs that defines the initial world state and gnome behaviors.

Traps An important pattern used to coordinate many gnomes.

Behavior

  • Gnomes act in discrete time steps, not in parallel.
  • All gnomes execute their current instruction before the next time step begins.
  • The program halts when all gnomes die.

Syntax

Headers

Header Description
[] The beginning and end of the header.
(a,b) Constructs gnome in garden a at position b.
[(a,b),(c,d),...] Constructs gnome in garden a at position b and garden c at position d.
a[b:c,d:e,...] Sets garden a's initial tape at b to c(0/1), and at d to e(0,1)
a:b[c,d,e,...] Sets garden a's initial tape starting at initial position b to c,d,e facing towards the right.
a:b-[c,d,e,...] Sets garden a's initial tape starting at initial position b to c,d,e facing towards the left.

A simple garden

[
(0,0) // make a gnome at garden 0, position 0
0:1[1,0,0,1]
]

This will create a garden that looks like

[... _ _ G 1 0 0 1 _ _ ... ]

Where G is the gnome.

Gnome Law

Instruction Description
a>b Move b steps in garden a (relative)
a>>b Move to absolute position b in a
a^ Read current cell in garden a
avb Write b(0/1) to garden a
@[(a,b),(c,d),...] Construct a new gnome at garden a, position b, garden c, position d.
! Die
a# Check if gnome is in garden a.
% Peek stack
? Pop stack
a$ Push integer a to stack
& Bitwise AND
| Bitwise OR
~ Bitwise NOT
+ Integer Add
- Integer Subtract
* Integer Multiply
/ Integer Divide
= Integer Equality

Control Flow

GnomeLang supports 3 kinds of loops and an if statement, constants, conditionals, and do-while conditionals

xxx { ... } // if statement
a ( ... ) // Constant Loop - runs loop exactly a times.
xxx ( ... ) // Conditional Loop
( ... ) xxx // Conditional do-while loop

Magic Gardens

Some gardens are more magic than others, for example Garden 13 is the standard out garden.

In garden 13 all bits rightward from index 0 are interpreted as ASCII. Setting cell 0 to 1 triggers output.

Traps

Traps are a very important design pattern to GnomeLang. In order to ensure all gnomes are working collectively and not against each other, gnomes can set traps to tell each other what they are doing. For example if a gnome would like to reserve a garden, the gnome should set a trap to let all other gnomes know the garden is reserved. The trap system can be extremely flexible, for example to figure out if an individual cell is reserved, you may dedicate an anti-garden, to reserve the cell set the equivalent anti-garden cell to 1.

Examples

Hello World

[
  13:0[1,0,1,0,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0,1,1,1,1,0,0,1,0,0,0,0,0,0,1,
  0,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,0,0,1,0,0,1,1,0,1,1,0,0,0,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,1,0
]

Unary Increment

[
  0:0[1,1,1,1]  // 1111 (unary 4)
  (0,0)
]
0ˆ1 { a>1 }     // Move right while '1'
0ˆ_ { 
    0v1
    ! 
}  // Write '1' at end and die

Garden Reservation Trap

$1 // start the search at garden 1
%>>-1 // move to absolute position negative 1 in garden 1
%ˆ1 { // if first garden is in use start loop, otherwise we've found an unused garden.
  (
    %< // leave garden
    ?+1$ //pop the current stack, increment by one and add back to stack
    %>>-1 // move to absolute position negative 1 in new garden
  ) %ˆ1 // if garden is still in use, repeat loop
}

Computational Class

GnomeLang is trivially Turing-complete, as a single Gnome and Garden can simulate a turing machine.