???Eiffel idiom for multiple return values??? 
Author Message
 ???Eiffel idiom for multiple return values???

Is there an idiom in Eiffel for functions which return multiple
values?

I have a class which conceptually has three integer attributes, one of
which is always zero.  A relationship among the three values exists
such that any one of the three can be set to zero by subtracting its
value from all three.  Thus, by always forcing the third value of the
three to be zero, only two integer attributes are actually required
and the storage requirements of the class are reduced.

The problem is that of course this is not the "natural" representation
for the values, so any manipulation requires that three local integers
be initialized by the class with the appropriate natural values.  This
must be done for nearly every functional attribute of the class, and
using three seperate calls to initialize each of the three locals
would entail a significant amount of redundant calculation.

In C/C++, I would simply declare a void function which took three
integer pointers/references as (out) parameters.  In a Lisp dialect I
could return a list or use multiple-value-bind.  What is the idiomatic
solution to this problem for Eiffel?
--
// Kaelin Colclasure ---------------------------------------------------------

// Voice: (314)567-8463                      717 Office Parkway
//   Fax: (314)432-5391                      St. Louis, MO 63141



Sat, 22 Mar 1997 03:40:03 GMT  
 ???Eiffel idiom for multiple return values???

Quote:

>Is there an idiom in Eiffel for functions which return multiple
>values?

...
>In C/C++, I would simply declare a void function which took three
>integer pointers/references as (out) parameters.  In a Lisp dialect I
>could return a list or use multiple-value-bind.  What is the idiomatic
>solution to this problem for Eiffel?

You could use a manifest array...

        feature
                init( ... ): ARRAY[ WHATEVER ] is
                do
                        ...
                        Result := << val1, val2, val3 >>;
                end;

----------
Ted Lawson



Wed, 26 Mar 1997 01:13:41 GMT  
 ???Eiffel idiom for multiple return values???

Quote:
Kaelin Colclasure writes:
> Is there an idiom in Eiffel for functions which return multiple
> values?
> > I have a class which conceptually has three integer attributes...

.
.

Quote:

> Voice: (314)567-8463                      717 Office Parkway//   Fax:
> (314)432-5391                      St. Louis, MO 63141

My approach is to return a reference to an instance of a class for which
these values are some of its features. eg:

class XYPAIR  -- A class that could be a point or a vector.
.
feature         x, y: REAL  -- The instance's current values.
        .
        make (initial_x, initial_y)
        .      
        All sorts of other features that do appropriate things
        with 'x' & 'y'...
        .

Then a feature in some other class that wants to return an XYPAIR
could look like this:

class SHIP
.
feature
        position: XYPAIR        -- Ship's position at sea.
        .
        make (lat,long: REAL...
                .
                !!position.make (lat, long)
                .
                .
        where: XYPAIR is        -- What is your position?
                is
                        Result := clone (position)      
                end
                .      



Tue, 25 Mar 1997 19:08:48 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Tuples, iterators, and multiple return values in Eiffel?

2. return multiple values from an awk function?

3. Wait ms Timer Multiple returning inaccurate timer value

4. multiple values in a return from function

5. Multiple return values

6. multiple return values

7. Multiple return values

8. Newbie on multiple return values

9. multiple return values for functions

10. Multiple return values

11. 1st-class method closures (was Re: Multiple return values)

12. C-interface and multiple return values

 

 
Powered by phpBB® Forum Software