comp.lang.ada
 help / color / mirror / Atom feed
* Re: Difference between a function and an operation
@ 1992-09-24 15:27 Julian C . Lander
  0 siblings, 0 replies; 3+ messages in thread
From: Julian C . Lander @ 1992-09-24 15:27 UTC (permalink / raw)


In article <PDB7L1R@math.fu-berlin.de>, weberwu@inf.fu-berlin.de (Debora Weber-
Wulff) writes:
|> Could someone either explain the distinction between an operation
|> and a function in Ada or quote chapter and versein the LMR? I understand tha
t
|> '+' and '*' and such are operations, and when I define a
|> function hugo to return a value, then that is a function. But
|> since I can overload '+' with function "+" (....) returns ...
|> they seem the same to me. 
|> Is there a difference, or are they synonymous?
|> -- 
|> Debora Weber-Wulff                       dww@inf.fu-berlin.de
|> Institut fuer Informatik                 +49 30 89691 124
|> Nestorstr. 8-9                           (INCLUDE "standard.disclaimer")
|> D-W-1000 Berlin 31                       (PRINTN (WITTY-MESSAGE TODAY))

You've got it right.  Operations in Ada are functions, which is why
the overloading works.  You can't overload the function "/=", because
that is defined to be the opposite of "=", which can be overloaded.

The operational notation is merely a notational convenience. I
don't remember offhand when you can use it for your own defined
functions, and I'm too lazy to check the LRM.

Julian C. Lander
jclander@mitre.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Difference between a function and an operation
@ 1992-09-25  2:19 portal!cup.portal.com!R_Tim_Coslet
  0 siblings, 0 replies; 3+ messages in thread
From: portal!cup.portal.com!R_Tim_Coslet @ 1992-09-25  2:19 UTC (permalink / raw)


In article: <1992Sep24.152726.17404@linus.mitre.org>
	jclander@texas.mitre.org (Julian C. Lander) wrote...
>You've got it right.  Operations in Ada are functions, which is why
>the overloading works.  You can't overload the function "/=", because
>that is defined to be the opposite of "=", which can be overloaded.
>
>The operational notation is merely a notational convenience. I
>don't remember offhand when you can use it for your own defined
>functions, and I'm too lazy to check the LRM.

The only functions that can use the "operational notation" are functions
of 1 or 2 parameters whose names are the predefined operators having
the same number of parameters (e.g. "+"(x,y), "-"(x,y), "-"(x), "*"(x,y),
"/"(x,y), ">"(x,y), "<"(x,y), etc....). It is not permitted in Ada to
name functions with "operator symbols" that are not already defined in the
language (e.g. "!"(x) could not be used to define a factorial operator
function of x).

It is possible to use the Renames declaration to rename a function
originally defined with a name so that it may now be refered to using
an operator notation (if it already has the matching number of parameters).

e.g.
	function "+"(x,y) renames fancy_sum(x,y);

(don't take the above example as correct Ada syntax, refer to the LRM
 for the right syntax for this statement. I left my LRM at work.)

                                        R. Tim Coslet

Usenet: R_Tim_Coslet@cup.portal.com
        technology, n.  domesticated natural phenomena

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Difference between a function and an operation
@ 1992-09-29 18:57 Robert I. Eachus
  0 siblings, 0 replies; 3+ messages in thread
From: Robert I. Eachus @ 1992-09-29 18:57 UTC (permalink / 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...

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1992-09-29 18:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-09-25  2:19 Difference between a function and an operation portal!cup.portal.com!R_Tim_Coslet
  -- strict thread matches above, loose matches on Subject: below --
1992-09-29 18:57 Robert I. Eachus
1992-09-24 15:27 Julian C . Lander

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