We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Macrosia

From Esolang
Jump to navigation Jump to search

Macrosia (formerly MacroScript) is an interpreted programming language created by balt in 2022[note 1], based on repeated text substitution. It provides macro functionality for the ROBOT IS CHILL Discord bot.

History and background

ROBOT IS CHILL is a Discord bot for generating images that mimic scenes from the video game Baba is You from text. From the beginning, it was very common to repeat certain tiles or variants when using the textual syntax. Thus, a primitive text substitution system was added, then simply called macros. It soon rapidly proliferated in terms of features and evolved into a complete programming language, initially being dubbed MacroScript, later being assigned the official name Macrosia. This can be compared to the evolution of ActionScript.

Overview

Execution is done in steps, each step substituting macro calls with their returned values until no calls are left. Despite its name, a macro is a runtime construct, closer to a function. Consider this example:

[add/5/10]
———
15

This is (almost) the simplest program possible, which reaches its output in only one step. Here's something more complex:

[[if/false/add/subtract]/5/10]

In this case, the macro name is a dynamic expression governed by the result of the if builtin. Since the condition is false, the next step yields:

[subtract/5/10]
———
-5

In a JavaScript-like pseudocode, this is equivalent to (false ? add : subtract)(5, 10).

Escaping

If you try to repeat a bare expression as if doing a loop in other languages, you probably won't get what you want:

[repeat/3/[rand] /]
———
0.6692248464484778 0.6692248464484778 0.6692248464484778 [note 2]

This brings us to escaping. By prepending [, / or ] characters in macro calls with a backslash, you can delay their execution:

[repeat/3/\[rand\] /]
———
\[rand\] \[rand\] \[rand\] 

...But now we've just outputted 3 calls to [rand]. How do we invoke them? Simple:

[unescape/[repeat/3/\[rand\] /]]
———
0.10304703431683992 0.6199976021577593 0.3242747476886283 [note 2]

The standard library

Also known as builtin macros; see Macrosia/Standard library for the full list.

The macro database

The language is tightly coupled with a public, centralized database of macros within ROBOT IS CHILL. Any Discord user can add a macro to the system; these range from aliases used in possibly hundreds of other macros to niche one-offs.

Using aliases from the database, the escaping example may be written as:

[u/[repeat/3/[_/rand] /]]

in order to circumvent backslashitis.

Implementations

Currently, the only implementation is the reference implementation in Rust. Two different web frontends are available:

Notes

  1. Uncertain.
  2. 2.0 2.1 These numbers are random; you will most likely get different results when running this code. If you do get the same numbers, please reach out to me.