From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 29 Sep 92 18:57:08 GMT From: eachus@mitre-bedford.arpa (Robert I. Eachus) Subject: Re: Difference between a function and an operation Message-ID: List-Id: In article weberwu@inf.fu-berlin.de (Debora Weber-W ulff) writes: Could someone either explain the distinction between an operation and a function in Ada or quote chapter and versein the LMR? I understand that '+' and '*' and such are operations, and when I define a function hugo to return a value, then that is a function. Hmmm... Tall order, I'll try to answer in a way that is consistant with the current ARG position. There are a number of overlapping terms involved, and Venn diagrams would be pretty useless. Let's start with 3.3(1): "A type is characterized by a set of values and a set of operations." Then go to 3.3.3(whole section): "The set of operations of a type includes the explicitly declared subprograms...The remaining operations are each implicitly declared...These implicitly declared operations comprise the basic operations, the predefined operators and enumeration literals." "A basic operation is...An assignment...selected component... qualification...type conversion...literal...aggregate...or an attribute." [Very heavily edited, and I intentionally ignored derived types.] Finally in 6.7(1): "The declaration of a function whose designator is an operator symbol is used to overload an operator." So there is a + for, say, integer which is a predefined operation. You may also declare: function "+" (L,R: Integer) return Integer; to overload the addition operator. What is the difference? The predefined operations of a type are always in scope, but they may be hidden, as above. In a generic only the predefined operations of a formal type parameter are visible, unless the operator is also passed as a formal parameter: generic type Int is range <>; -- a generic formal integer type. with function "+"(L,R: Int) return Int is <>; -- use the "+" for the actual parameter corresponding to Int -- and visible at the point of instantiation. This may be -- the predefined operation. package... Also if you derive from a type, any subprograms (with a parameter or result of the type) declared in the same package specification as the parent type are derivable, and are available for the derived type also. In this there is no distinction between predefined and other operations. Summary: A type has basic operations, predefined operators, and explicitly declared operations (possibly including enumeration literals). Derived types also have derived operations. (In the case of a derived enumeration type, the enumeration literals are derived operations.) The predefined operations include the basic operations and the predefined operations. -- Robert I. Eachus with STANDARD_DISCLAIMER; use STANDARD_DISCLAIMER; function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...