iyi

Playground · Basics · 6 of 33

conversions

Conversions are explicit: nothing changes type on its own.

samples/tour/conversions.iyi · conversions.wasm · 182 KB
# Conversions are explicit: nothing changes type on its own.

n = 42
puts n.to_f
puts n.to_s + "!"

f = 9.99
puts f.to_i
puts f.round(1)

# From text. `to_i` expects a number; `to_i?` answers nil when there is none.
puts "17".to_i + 1
puts "17".to_i?
puts "seventeen".to_i?

# A Char is a byte, and its code is a number.
puts 'A'.ord
puts 66.chr
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 conversions.wasm, the module the compiler built from this file, in your browser. How this works

Try it on your machine

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

sh, after installing
$ iyi run conversions.iyi