[ All Fragments ]
Dylan functions (and other expressions) can return more than one value. Essentially, every function has a list of parameters and a list of results. There's no need to pass pointers to empty data structures just to get values back.
This example also includes a class definition. Classes and objects will be covered in more detail in later examples. Notice that Dylan comments look like C comments.
// Position is measured in meters (relative to the ground), time in seconds, // and velocity in meters per second. define class <rock> (<object>) slot initial-position :: <float>, required-init-keyword: position:; slot initial-velocity :: <float>, required-init-keyword: velocity:; end class; define function find-position-and-velocity (rock :: <rock>, time :: <float>) => (position :: <float>, velocity :: <float>) values(-4.9 * time * time + rock.initial-velocity * time + rock.initial-position, -9.8 * time + rock.initial-velocity); end function; define function print-position-and-velocity (rock :: <rock>, time :: <float>) => () let (p, v) = find-position-and-velocity(rock, time); format-out("Position: %=m, Velocity: %=m/s\n", p, v); end function; define variable *rock* = make(<rock>, position: 10.0, velocity: 0.0); print-position-and-velocity(*rock*, 1.0);