djana@watdragon.waterloo.edu (Debasish Jana) (12/22/89)
Is there any way to pass parameters to a function by name, by value in Eiffel or does it use call by reference only? Thanks in advance. Debasish. ---------- Debasish Jana. djana@dragon.waterloo.edu, djana@dragon.uwaterloo.ca
bertrand@eiffel.UUCP (Bertrand Meyer) (01/11/90)
From <19453@watdragon.waterloo.edu> by djana@watdragon.waterloo.edu: > Is there any way to pass parameters to a function by name, by value in Eiffel > or does it use call by reference only? There are two kinds of values in Eiffel: references and objects. An entity declared of class type denotes a reference; an entity declared of expanded type denotes an object. For example: a: LINKED_QUEUE [X] -- Reference (class type) s: STRING -- Reference (STRING is a class of the basic library) s: expanded POINT -- Object (expanded type) n: INTEGER -- Object (expanded type) As the last example indicates, the basic types INTEGER, REAL, DOUBLE, CHARACTER and BOOLEAN are treated as expanded class types. All argument passing is done by value: the actual argument is (conceptually) copied into the formal argument). What is copied is the reference (for a class type) or the object (for an expanded type). From a practical perspective, however, a reference is not interesting in itself; what is interesting is the object it refers to (the official terminology is that a reference IS ATTACHED TO an object). Then if you consider the object of interest in both the expanded type and the class type cases, what you get is essentially - Passing by reference for formal arguments of class type. - Passing by value for formal arguments of expanded type. Note that the mode is determined by the target (the formal argument). This makes it possible to have very convenient transformations between references and objects. The transformations are purely conceptual and do not cost any computation time. For details, please see the book ``Eiffel: The Language''. -- -- Bertrand Meyer bertrand@eiffel.com