Logicode
Three logic gates and a way to wire them into circuits. Everything else, numbers and text included, you build yourself.
Qwerp-Derp, 2016 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 7 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Qwerp-Derp designed Logicode on 31 August 2016, after the circuit simulator Logisim. Every value is a list of bits. The language gives you AND, OR and NOT, and a circuit is a function you wire from them. An XOR gate is one line, a half adder is the next, and from there you can build counters and adders.
Read the story
Text is a side door. @ reads a list of bits as a binary number and turns it into the character with that code, so @1001000 is H. The Hello World builds l and o once and reuses them.
The machine
| Code | Does |
|---|---|
0110 | A list of bits |
a&b a\|b | AND and OR, bit by bit, the shorter list padded with zeros on the left |
!a ~a *a | Flip every bit, reverse, 1 if any bit is 1 |
@a | The character whose code is the bits, modulo 256 |
a> a< | Drop the first bit, keep only the first bit |
a+b | Join two lists |
var x=expr | A variable |
circ f(a,b)->expr | A circuit; with [ and ] it takes several lines and gives the last value |
cond c->x/y | Do x if c has a 1 in it, otherwise y |
out expr | Print the bits, then a newline |
ainp binp | A line of input as 8 bits per character, or as its 0 and 1 digits |
? | A random bit |
There are no loops. A circuit can call itself, so repetition is recursion, and the reference interpreter's own test programs count the length of a bit string that way.
Example
The half adder gives the carry and the sum of two bits.
The half adder gives the carry and the sum of two bits. With input waiting, ainp still prints the reference's prompt Input: before it reads the line.
Patterns it teaches
- Turing tarpit: three gates, concatenation and recursion are all there is.
- Encoding tricks: every number and every character is spelled out in binary.
Further
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Logicode
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: logicode.
Command line
shib run logicode -e 'out ainp' --input 'A
'shib manual logicodeSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/logicode.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org