esolang

Macrosia

Text with calls in brackets, where each step replaces the innermost calls by what they return.

balt, 2022 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 15

The idea

balt made Macrosia, first called MacroScript, for ROBOT IS CHILL, a Discord bot that draws scenes in the style of the game Baba Is You from text. It began as plain text substitution to save typing the same tiles again and again, and grew into a whole language. It dates from 2022.

Read the story

A program is a piece of text, and a call in it is [name/argument/...]. Each step replaces every call that has no other call inside it by its result. Then the text is read again, and new calls made by the last step run in the next one. The name of a macro can itself be the result of a call.

A backslash in front of [, / or ] keeps it from being syntax for now. The backslash stays in the text until unescape takes it away, so code can be passed around as text and run later.

The machine

CallGives
[add/5/10] [subtract/5/10]15 and -5
[if/false/add/subtract]subtract
[repeat/3/ab/-]ab-ab-ab
[unescape/\[add\/1\/2\]][add/1/2], which the next step turns into 3

This implementation has only these five builtins, the ones the specification itself uses. Left out are the rest of the standard library, rand, whose numbers are random, and the bot's database of macros written by its users.

Example

Two calculations.

Two calculations. The second takes two steps, as if picks the name of the macro first.

Expected: -5

Escaped calls are only text, so repeat copies them with their backslashes.

Expected: \[rand\] \[rand\] \[rand\]

With unescape around it, the three copies become calls of their own. With rand the specification gets three different random numbers this way. The same idea runs on add.

Expected: 3 3 3

Patterns it teaches

Further

Markup languages

String-rewriting paradigm

Write your own in Run Convert a program from Macrosia

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run macrosia -e '[add/5/10]'
shib manual macrosia

Source

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

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

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