comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@mitre-bedford.arpa  (Robert I. Eachus)
Subject: Re: Difference between a function and an operation
Date: 29 Sep 92 18:57:08 GMT	[thread overview]
Message-ID: <EACHUS.92Sep29135708@Dr_No.mitre.org> (raw)

In article <PDB7L1R@math.fu-berlin.de> 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...

             reply	other threads:[~1992-09-29 18:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-09-29 18:57 Robert I. Eachus [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-09-25  2:19 Difference between a function and an operation portal!cup.portal.com!R_Tim_Coslet
1992-09-24 15:27 Julian C . Lander
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox