iyi

Playground · Basics · 9 of 33

returns

More than one result: a tuple, unpacked at the call.

samples/tour/returns.iyi · returns.wasm · 123 KB
# More than one result: a tuple, unpacked at the call.

def divide(a : Int32, b : Int32) : Tuple(Int32, Int32)
  {a // b, a % b}
end

quotient, remainder = divide(17, 5)
puts quotient
puts remainder

# A tuple is a value like any other.
pair = divide(9, 4)
puts pair[0]
puts pair[1]

# `return` leaves early, and can carry a value.
def first_even(numbers : Array(Int32)) : Int32?
  numbers.each do |n|
    return n if n % 2 == 0
  end
  nil
end

puts first_even([1, 3, 6, 7])
puts first_even([1, 3])
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 returns.wasm, the module the compiler built from this file, in your browser. How this works

Try it on your machine

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

sh, after installing
$ iyi run returns.iyi