esolang

Object oriented Thue

Thue, where the string can hold objects, and every object carries a string and rules of its own.

4D enthusiast, 2012 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, World!

The idea

4D enthusiast made Object oriented Thue in 2012. It keeps Thue's rules, lhs::=rhs, which replace text anywhere in a string in any order. On top of that, {Name} in the string is an object of the class Name. Rules outside a class can move or copy an object only as a whole. Rules inside a class work on the object's own inner string, which nothing outside can see.

Read the story

Inside a class, a lone { or } is the edge of the object itself. So }a::=a} pulls the a to its right inside, and {a::=A{ pushes an A out to its left. Objects can carry data across other text and let it out on the other side. Classes can inherit rules, and a subclass cancels one by repeating it.

Thue's output, a rule whose right side starts with ~, is gone. Input and output come from the library stdio instead. {TextOutput} prints whatever text lies to its right, and a line typed at the keyboard appears before every {TextInput}.

The machine

LineMeans
lhs::=rhsA rule; inside a class it works on that class's objects
Name ... }A class; lines after the name that are not rules name its superclasses
{Duck}{1}On the right side, the second Duck of the left side; a number past them makes a new one
{textA comment
import stdioBrings TextInput, TextOutput, HexInput and HexOutput
last lineThe starting string

TextOutput reads \n, \(, \), \/ and \Uxxxx as a line break, braces, a backslash and a character. The specification leaves open which rule fires when several could. A TextOutput prints first if it can, then the first rule in the program that applies rewrites its first place, then the next line of input arrives. stdfile and stdtime are not.

Example

The Convert class, with a TextOutput in front.

The Convert class, with a TextOutput in front. The object swallows abba letter by letter and lets it out on its left in capitals, and the TextOutput prints what comes out.

Expected: ABBA

The cat needs no rules at all. The typed line arrives escaped, so the braces print as braces.

Expected: echo {this}

The 99 bottles of beer keeps its count in a Number object that holds two Digit objects. It takes 4,860 rewrites, and its TextOutputs print 11,456 characters.

Patterns it teaches

Further

Object-oriented paradigm

Nondeterministic

Write your own in Run Convert a program from Object oriented Thue

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: object-oriented-thue.

Command line

shib run object-oriented-thue -e 'import stdio
{TextOutput}Hello, World!'
shib manual object-oriented-thue

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/object-oriented-thue.js

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

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