[ All Fragments ]
Every Dylan statement or expression returns a value. Control constructs and functions return the value of the last expression in their body.
define function absolute-value(x :: <integer>)
=> (result :: <integer>)
if (x >= 0)
x;
else
-x;
end;
end;
Several other aspects of Dylan are visible in this example:
Dylan allows "-" characters in the middle of names. Other
strange characters are allowed as well, which means that names must often
be surrounded by whitespace, parentheses or punctuation. Dylan's
designers apparently liked hitting the space bar more than they liked
hitting the shift key.
Type names are surrounded by angle brackets
("<integer>"). This is just a naming convention. You'll
see more strange characters at the begining and end of other names.
Blocks of code begin with a normal header, but don't have an
{ bracket or a begin statement. This saves
typing. Blocks do, however, have an end keyword at the
bottom. You can omit semi-colons at the end of blocks.