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
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.
| Component | Does |
|---|---|
"…" .c | A 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 a | Duplicate, swap |
, L | Print 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…
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.
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
- Code golf: input fills in for missing arguments.
- Stack machines: one stack, with depth rules deciding when to map.
Try this
- Print the numbers 10 down to 1.
- Read two lines and print the larger number.
- Hard: print the squares of 1 to 10 as whole numbers.
Further
- The reference interpreter, in Ruby, version 1
- Related: Ohm v2, 05AB1E
See also
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 ohmSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/ohm.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language