iyi

Playground

samples/iyi/formatting.iyi

Negative indexing and the small formatting set — README "What is not here".

samples/iyi/formatting.iyi · iyi-formatting.wasm · 139 KB
# Negative indexing and the small formatting set — README "What is not here".
#
#   ./bin/iyi run samples/iyi/formatting.iyi
#
# `a[-1]` counts from the end. `to_s(base)` writes a number in base 2 through
# 36. `rjust` / `ljust` pad, `*` repeats. There is no format-string parser;
# these are the methods a table and a hex dump actually need.

module samples/formatting

a = [10, 20, 30]
puts "last #{a[-1]}"
puts "first #{a[-a.size]}"

a[-1] = 99
puts "written #{a[-1]}"

s = "hello"
puts "char #{s[-1]}"
puts "slice #{s[-2, 2]}"

n = 255
puts "hex #{n.to_s(16)}"
puts "bin #{5.to_s(2)}"

cell = "ab"
puts "rjust '#{cell.rjust(5)}'"
puts "ljust '#{cell.ljust(5, '*')}'"
puts "rep #{cell * 3}"

puts "nil #{a[-4]?.inspect}"
puts "maybe #{a[-1]?.inspect}"
output
Press Run.

recorded with iyi 0.18.0 (built on Crystal 1.22.0-dev [2a9653052] (2026-10-18)) · Linux 7.0.0-38-generic x86_64, QEMU Virtual CPU version 2.5+ · 2026-10-19

You can type in the pane: nothing here compiles, so what you type cannot run, and the page says which bytes it is running the moment the text stops being the recorded file. There is no standard input, no filesystem and no threads on this target, and one sample fails on purpose for exactly that reason.

Run executes iyi-formatting.wasm, the module the compiler built from this file, in your browser. How this works

Try it on your machine

Copy the program into formatting.iyi, change something, and run it. Only a compiler on your own machine can run what you wrote.

sh, after installing
$ iyi run formatting.iyi