Everything is a value#
Every Dylan statement or expression returns a value. Functions and control
constructs like select
and for
return the values of the last
expression in their body.
if
returns a value so it may be used in return position:
let abs = if (x >= 0) x else -x end;
Dylan functions return the values of the last expression in their body to be evaluated. This function returns either “foo” or “bar”:
define function foobar ()
if (odd?(random(100)))
"foo"
else
"bar"
end
end;
If there is no return value declaration for a function then any number of
values of any type can be returned. Use => (...decls...)
to declare return
values. This function returns no values:
define function foo () => ()
format-out("foo");
end;
This function returns an integer and a string:
define function bar () => (size :: <integer>, description :: <string>)
values(42, "the meaning of everything")
end;