esolang

match

A function is a list of patterns. The first one that fits says what to do.

Japi, 2024 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, world!

The idea

Japi made match in 2024. Every function takes one argument and is written as branches, a pattern on the left of -> and an expression on the right. A call tries the branches in order and runs the first whose pattern fits. There are no loops and no variables to change, so repetition is recursion.

Read the story

Since there is only one argument, more arguments travel as a pair or a list. The comma makes a pair and groups to the right, so 1, 2, 3, nil is a list of three, and a string is a list of characters.

The machine

PartDoes
name: p -> e; ...;;A function, each branch ending in ; and the last in ;;
p: guard -> eA branch that also needs the guard to be true
_ x 1 'a' nil x, xsPatterns for anything, a name, literals and a pair
+ - * / % < > =Arithmetic and comparison
a, bA pair
a then bRun a, give b
f(x)Call, with the commas inside making one list

print, println, readln and error are built in, and the program starts by calling main. Numbers are 64-bit floats and print the way the Rust interpreter prints them, so 10 and not 10.0. include reads another file, and is left out because a run has no other files.

Example

The sum of a list from the specification.

The sum of a list from the specification. An empty list is 0, and otherwise the head is added to the sum of the tail.

Expected: 10

The truth machine matches the line it reads as a list of characters. On 1 it would print 1 and call itself forever.

Expected: Type a '0' or '1': 0

filter keeps what a function passed with the list says yes to. With its even and the sum above it adds 2, 4 and 6.

Expected: 12

Further

Declarative paradigm

Functional paradigm

Write your own in Run Convert a program from match

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run match -e 'main: _ -> println("Hello, world!");;'
shib manual match

Source

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

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

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