[Main website]

dok/spec/return-multiple-values

In Dok, like in CL, a function can return a result with optional attributes. For example the integer division can return the rest as optional attribute. The run-time should support this behavior in an efficient way.

Int.div(x::Int)::Int[slot rest::Int] {
  var x::Int self.floor(x)
  var y::Int self.ceil(x)
  var r::Int y - x

  return x(with rest r)
}

var t::Int 5.div(2)

assert t.isa(Int)
assert t == 2

assert t.isa(Int[slot rest::Int])
assert t.rest == 1