esolang

OML

Ordinal Manipulation Language. One stack of 64-bit integers and a command for nearly every printable character.

Conor O'Brien · Turing complete: unknown · ●●○ moderate

Tested with 5 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

OML is a golfing stack language by Conor O'Brien, interpreted by a single C file. Every value is a signed 64-bit integer, so a string is just a run of character codes with its length on top. "Hello" pushes the five codes, first letter on top, and then a 5; s pops that length and prints that many characters. Whatever is left on the stack at the end is printed, one number per line, top first.

Read the story

Popping an empty stack quietly gives 0, which golfed programs lean on.

The machine

CodeDoes
0…9 A…FPush 0 to 15; G H I J S push 64, 256, 100, 1000, 16
"text" 'cPush the bytes of a text (last first) and its length; push one byte
+ - * / % .Arithmetic on the top two, . gives quotient and remainder
` ! n m N M | Power, factorial, square, cube, integer square and cube root
< = > & \| ^ ~ _Compare, bit operations, negate
$ : ; , @Drop, duplicate, over, swap, rotate
( )Loop while the top is not 0, without popping it
{ }Pop, and skip to } if it was 0
# o sPrint a number, a character, a string of n characters
h i jRead a number, a line, a byte
fx gxStore into and recall variable x
P QSet the input and output base

There are more, among them register stacks, sub-stacks, digit lists and a dozen commands behind an e prefix.

This implementation follows OML.c, the interpreter Try It Online runs. It keeps the C details, such as division rounding toward zero, numbers that wrap at 64 bits, and a character from o that waits in the output buffer and is lost if the program then crashes. Left out are the few e commands that work with decimal numbers or memory addresses.

Example

The second program counts down.
Expected: 5 4 3 2 1 0
Expected: 42
Expected: 720
Expected: 101

The second program counts down. Each round duplicates the counter, prints it, prints a newline (A is 10 and o prints it as a character) and subtracts one. The loop ends when the top is 0, and that 0 is left on the stack, so the end of the program prints it. The last program switches the output to base 2.

Patterns it teaches

  • Stack machines: strings, numbers and loop counters share one stack of integers.
  • Code golf: single characters for whole operations, and an empty stack that answers 0.

Try this

  1. Print the numbers 1 to 10.
  2. Read a line and print it backwards.
  3. Hard: print the first ten Fibonacci numbers.

Further

Also in Functional and concatenative

Write your own in Run Convert a program from OML

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run oml -e 'is' --input 'Hi there
'
shib manual oml

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/oml.js

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