esolang

Zed

One memory value, one stack, two kinds of loop and a name for any piece of code.

2019 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: ABC

The idea

Zed is a language of 32 one-character commands from 2019, listed among the descendants of brainfuck. A program works on a single memory value, a signed 64-bit number, and a stack of such numbers. ( repeats its body as many times as the memory says when the loop starts, and [ repeats it until the memory is 0. A name written right before [ saves the code in the brackets as a function, and the name on its own runs it.

Read the story

The specification calls Zed a work in progress and gives each command a few words. Half of them, for threads, scopes, delays, the clock and jumps in the program, are not described well enough to build, so this implementation leaves them out.

The machine

CommandDoes
+ -Add or take 1
/ \ ~Set the memory to the largest 64-bit number, to 0, or to minus itself
! ?Push the memory; pop into it
%Set the memory to the size of the stack
. ,Print or read a Unicode character
( ... )Repeat as many times as the memory says
[ ... ]Repeat until the memory is 0
name[ ... ]Save a function
nameRun it
` | End the program

Left out are : ; * < > { } # & = " ' $ @ | ^ _, which restart and complete a run, wait, start and end threads, open scopes and pass values between them, move the execution position, toggle a debug mode and read the clock. So are the variables a name makes with (.

Example

All three are from the specification.
Expected: !dlroW ,olleH
Expected: ABC

All three are from the specification. In the first, ++++ makes 4 and the outer loop runs four times. Each time the inner (+) adds 1 as many times as the memory holds, so it doubles, and 4 becomes 64. Then +. three times prints A, B and C.

The reverse program reads characters and pushes them until a read gives 0 at the end of the input. It pops that 0, sets the memory to the size of the stack, and pops and prints that many times. The third program saves the doubling as dbl and calls it four times.

Patterns it teaches

Further

Zed builds on Brainfuck.

Brainfuck derivatives

Stack-based

Write your own in Run Convert a program from Zed

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run zed -e '+[,!]?%(?.)' --input 'Hello, World!'
shib manual zed

Source

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

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

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