ahodgson@hstbme.mit.edu (Antony Hodgson) (09/01/90)
I have often found myself writing functions in which there is one or more "input" variable and more than one output (for example, a routine which computes both the eigenvalues and corresponding eigenvectors of a matrix or anything which returns a structure/object and an error code). Such functions have prototypes which look like the following: void EigenStuff( Matrix A, Vector EVals, Matrix EVectors ) or errorcode SomeFunction( int i, Object X ) This syntax does not make clear which of the parameters in the prototypes are used as input values and which are return values. I was thinking that a clearer syntax might be something like the following: void (Vector Evals, Matrix EVectors) EigenStuff( Matrix A ) and errorcode (Object X) SomeFunction( int i ) and the functions could be used as follows: ( EVals, EVectors ) = EigenStuff( A ) and if ( (X) = SomeFunction(i) == BAD_NEWS ) ... This syntax makes clear which parameters are required as input and which are computed and returned by the function. It also is fully compatible with existing code. There may be some problem with variables which are passed by reference since they can be both input and output, but even so, this syntax might be clearer: errorcode ( Matrix &A ) MatrixInverse( Matrix &A ) used as: if ( (A) = MatrixInverse(A) == NON_SINGULAR ) ... Does anyone think this is a good idea, or is it simply, in the words of one recent contributor, a minor convenience but not a solution to a significant problem? Your comments are appreciated. Tony Hodgson ahodgson@hstbme.mit.edu
diamond@tkou02.enet.dec.com (diamond@tkovoa) (09/03/90)
In article <1990Aug31.234937.29938@athena.mit.edu> ahodgson@hstbme.mit.edu.UUCP (Antony Hodgson) writes: >I was thinking that a clearer syntax might be something like the following: > void (Vector Evals, Matrix EVectors) EigenStuff( Matrix A ) >and errorcode (Object X) SomeFunction( int i ) >and the functions could be used as follows: > ( EVals, EVectors ) = EigenStuff( A ) >and if ( (X) = SomeFunction(i) == BAD_NEWS ) ... I like this idea. I have redirected it to comp.lang.misc, where it belongs. Don't look for it to be added to an existing language. -- Norman Diamond, Nihon DEC diamond@tkou02.enet.dec.com We steer like a sports car: I use opinions; the company uses the rack.