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
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
| Line | Means |
|---|---|
lhs::=rhs | A 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 |
{text | A comment |
import stdio | Brings TextInput, TextOutput, HexInput and HexOutput |
| last line | The 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.
The cat needs no rules at all. The typed line arrives escaped, so the braces print as braces.
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
- String rewriting: objects are text that rules can only move whole.
- Nondeterminism: the order of the rules is left open.
See also
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-thueSource
- 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