Task

Show how to return more than one value from a function.




% Returning multiple values (along with type parameterization)
% was actually invented with CLU.
 
% Do note that the procedure is actually returning multiple
% values; it's not returning a tuple and unpacking it. 
% That doesn't exist in CLU.
 
% For added CLU-ness, this function is fully general, requiring
% only that its arguments support addition and subtraction in any way
 
add_sub = proc [T,U,V,W: type] (a: T, b: U) returns (V, W)
          signals (overflow)
          where T has add: proctype (T,U) returns (V) signals (overflow),
                      sub: proctype (T,U) returns (W) signals (overflow)
    return (a+b, a-b) resignal overflow
end add_sub 
 
 
% And actually using it
start_up = proc ()
    add_sub_int = add_sub[int,int,int,int] % boring, but does what you'd expect
    po: stream := stream$primary_output()
 
    % returning two values from the function
    sum, diff: int := add_sub_int(33, 12)
 
    % print out both
    stream$putl(po, "33 + 12 = " || int$unparse(sum))
    stream$putl(po, "33 - 12 = " || int$unparse(diff))
end start_up