esolang

Beautiful day

A grammar that runs. Every rule that fits opens a branch, and the answer is whether the input can be built.

Hakerh400, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: 1

The idea

Hakerh400 made Beautiful day in 2020 as a branching cousin of Golden sunrise. The rules have the same shape, but they work on any characters, and where Golden sunrise lets only one rule fit a group, every rule that fits is followed in a branch of its own. A program is a grammar, and its output is one bit, 1 when the input is one of the strings it can build.

The machine

A rule is left - right;. The left side says what a group's content starts with, and the right side is what the whole group becomes.

RuleDoes
ab - x(y).;A group starting with ab becomes x, a group holding y, then the rest after ab
ab# - z;A group holding exactly ab becomes z
/ - z;Any group becomes z
c - /;A group starting with c disappears

The run starts from one empty group, (). A branch where no rule fits dies, and a branch with no group left has built a string. The characters \ / # - . ( ) ; and spaces are written with a backslash in front, except that parentheses on the left side are plain characters.

The specification leaves open which group is rewritten first. This implementation always rewrites a group with no group inside it, the first from the left. That is the reading under which the palindrome program builds only palindromes, because the letter inside (func(letter)) is chosen before func copies it to both ends.

Example

The first program builds zero or more letters A.

The first program builds zero or more letters A.

The second builds palindromes of A, B and C. Each func puts a palindrome between two copies of one letter.

Expected: 1

For a string outside the set the specification allows 0 or a run that never ends. Letters outside every group never change, so this implementation cuts a branch once they no longer fit the input. For ABCA every branch is cut and the answer is 0.

Expected: 0

Patterns it teaches

Further

String-rewriting paradigm

Functional paradigm

Write your own in Run Convert a program from Beautiful day

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: beautiful-day.

Command line

shib run beautiful-day -e '# - (c);
a - (b)(c);
b - A;
c - /;
c - (a);' --input 'AAAA'
shib manual beautiful-day

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/beautiful-day.js

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

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