esolang

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

Expected: Hello, World!

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

CodeDoes
0110A list of bits
a&b a\|bAND and OR, bit by bit, the shorter list padded with zeros on the left
!a ~a *aFlip every bit, reverse, 1 if any bit is 1
@aThe character whose code is the bits, modulo 256
a> a<Drop the first bit, keep only the first bit
a+bJoin two lists
var x=exprA variable
circ f(a,b)->exprA circuit; with [ and ] it takes several lines and gives the last value
cond c->x/yDo x if c has a 1 in it, otherwise y
out exprPrint the bits, then a newline
ainp binpA 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.
Expected: 10
Expected: Input: 01000001

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

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 logicode

Source

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