Return multiple values: Difference between revisions

Add CLU
(Added solution for Action!)
(Add CLU)
Line 520:
(println r))</lang>
 
=={{header|CLU}}==
<lang clu>% 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</lang>
{{out}}
<pre>33 + 12 = 45
33 - 12 = 21</pre>
=={{header|CMake}}==
<lang cmake># Returns the first and last characters of string.
2,114

edits