How to resolve the algorithm Return multiple values step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Return multiple values step by step in the CLU programming language

Table of Contents

Problem Statement

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

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Return multiple values step by step in the CLU programming language

Source code in the clu programming language

% 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

  

You may also check:How to resolve the algorithm Peano curve step by step in the Python programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the IDL programming language
You may also check:How to resolve the algorithm Read entire file step by step in the Retro programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Sidef programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the ERRE programming language