esolang

Ohm

The first version of a Ruby golfing language, with floats for numbers and a CP437 code page of box-drawing commands.

nickbclifford · Turing complete: yes · ●●○ moderate

Tested with 7 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: Hello, World!

The idea

Ohm was made by nickbclifford for code golf, after 05AB1E and Jelly. This is version 1, which Try It Online keeps on the v1 branch of the repository nickbclifford/Ohm. Its commands come from the old IBM PC code page, so loops are written with ∞ and ■ and many components are box-drawing characters. Ohm v2 followed with BigDecimal numbers.

Read the story

A program is a row of components on one stack. When a component needs more values than the stack holds, each missing one is a fresh line of input. When the program ends without printing, the top of the stack is printed.

The machine

A number literal is pushed as text, and arithmetic reads it with Ruby's to_f. So 13 2+ gives the float 15.0. Numbers are printed with %g and as many digits as the number's own text has characters, so 15.0 prints as 15 but one third prints as 0.333333333333333315. True and false stay true and false.

ComponentDoes
"…" .cA string (Ñ inside is a newline), one character
+ - * / %Float arithmetic
< >Compare, giving true or false
@ #The list 1 to n, 0 to n
l R S J ΣLength, reverse, sort, join, sum
D aDuplicate, swap
, LPrint with and without a newline
?…¿…;If, else; only false and nil are false
:…;For each, with the value in _ and the index in ^
M…; ∞…;Repeat n times, repeat until ■

Example

The float one third has 18 characters as text, so it is printed with 18 significant digits, and the last…
Expected: 15
Expected: 1 2 3 4 5
Expected: 0.333333333333333315

The float one third has 18 characters as text, so it is printed with 18 significant digits, and the last ones show the binary value underneath.

Expected: true
Expected: 144

This implementation is a subset. It has 39 of the components and five kinds of block. The rest, the other lines of a program and the compressed strings stop the run with a reason.

Patterns it teaches

Try this

  1. Print the numbers 10 down to 1.
  2. Read two lines and print the larger number.
  3. Hard: print the squares of 1 to 10 as whole numbers.

Further

Also in Golfing

Write your own in Run Convert a program from Ohm

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run ohm -e '²' --input '12'
shib manual ohm

Source

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

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