esolang

Xand

One instruction on bits. A line x, y, z sets x to (x xor y) and z, and every gate is built from that.

Turing complete: no · ●○○ easy · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: a: 1

The idea

Xand is a one instruction language. Its variables hold one bit each, and its only instruction sets x to (x xor y) and z. The names 0 and 1 hold the constants, so a, 1, 1 flips a, a, 0, b ands a with b and a, 0, 0 clears it. The specification builds Not, And, Nand, Or, Nor, Set and three kinds of Shift out of these three moves.

Read the story

The first line names the inputs in brackets. When the last line has run, every variable is printed with its value, the inputs first.

The machine

LineDoes
(a, b)The first line, reads a and b from the input
x, y, zSets x to (x xor y) and z
loop, L, 0Marks this line as the label L
loop, v, LGoes back to the label L when v is 0
#Starts a comment

Only the specification's Python interpreter has loop. An input is 1 for any number but 0. A name that is new holds 0, which the Shift needs for its spare c. The interpreter as printed takes the program a character at a time where it means a line at a time, and fails on the first one. Its jump also sets only a local copy of the line number, so it would never go back. This implementation does what both mean.

Example

The Not and And, with the first part of their comments.

The Not and And, with the first part of their comments.

Expected: a: 1 b: 1

The Or flips both inputs on the way and leaves b flipped.

Expected: a: 1 b: 0

The Shift swaps a and b through a spare c.

Expected: a: 0 b: 1 c: 1

The Nand is not quite NAND. It sets a to (not a) and b, which is 0 when a and b are both 0.

Expected: a: 0 b: 0

Patterns it teaches

Further

OISC

Write your own in Run Convert a program from Xand

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: xand.

Command line

shib run xand -e '(a, b)
a, 1, 1
b, 1, 1
a, 0, b' --input '0 0'
shib manual xand

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/xand.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org