comp.lang.ada
 help / color / mirror / Atom feed
* Why is abs an operator, not a function?
@ 2006-10-18  5:13 Jerry
  2006-10-18  7:30 ` Dmitry A. Kazakov
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jerry @ 2006-10-18  5:13 UTC (permalink / raw)


Why is abs an operator and not a function? Just wondering.

Is there no way to write a function abs() that, say, computes the
absolute value of each of the components of a float array?

Jerry




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

* Re: Why is abs an operator, not a function?
  2006-10-18  5:13 Why is abs an operator, not a function? Jerry
@ 2006-10-18  7:30 ` Dmitry A. Kazakov
  2006-10-18  7:36 ` Samuel Tardieu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2006-10-18  7:30 UTC (permalink / raw)


On 17 Oct 2006 22:13:46 -0700, Jerry wrote:

> Why is abs an operator and not a function? Just wondering.

To be able to use it without brackets, I suppose. However the idea to make
a reserved word out of "abs" was IMO crank.

> Is there no way to write a function abs() that, say, computes the
> absolute value of each of the components of a float array?

How so?

   type Float_Array is array (Integer range <>) of Float;

   function "abs" (X : Float_Array) return Float_Array is
      Result : Float_Array (X'Range);
   begin
      for Index in X'Range loop
         Result (Index) := abs X (Index);
      end loop;
      return Result;
   end "abs";

And also:

   X : Float_Array := ...;
   Y : Float_Array := abs (X); -- This is legal and equivalent to abs X

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Why is abs an operator, not a function?
  2006-10-18  5:13 Why is abs an operator, not a function? Jerry
  2006-10-18  7:30 ` Dmitry A. Kazakov
@ 2006-10-18  7:36 ` Samuel Tardieu
  2006-10-19  1:45 ` Robert A Duff
  2006-10-23  2:39 ` Jerry
  3 siblings, 0 replies; 6+ messages in thread
From: Samuel Tardieu @ 2006-10-18  7:36 UTC (permalink / raw)


>>>>> "Jerry" == Jerry  <lanceboyle@qwest.net> writes:

Jerry> Why is abs an operator and not a function? Just wondering.  Is
Jerry> there no way to write a function abs() that, say, computes the
Jerry> absolute value of each of the components of a float array?

Of course there is :) You can overload operators as well in Ada, just
use the name "abs" (including the quotes).

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/



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

* Re: Why is abs an operator, not a function?
  2006-10-18  5:13 Why is abs an operator, not a function? Jerry
  2006-10-18  7:30 ` Dmitry A. Kazakov
  2006-10-18  7:36 ` Samuel Tardieu
@ 2006-10-19  1:45 ` Robert A Duff
  2006-10-19  4:30   ` Keith Thompson
  2006-10-23  2:39 ` Jerry
  3 siblings, 1 reply; 6+ messages in thread
From: Robert A Duff @ 2006-10-19  1:45 UTC (permalink / raw)


"Jerry" <lanceboyle@qwest.net> writes:

> Why is abs an operator and not a function? Just wondering.

An operator _is_ a function.  So the question really is, why is the name
of the abs function an operator symbol (a reserved word) rather than an
identifier?

In early (pre-1983) versions of Ada, Abs was not an operator -- just a
normal function with identifier Abs as its name.  I think it was changed
to make implementations easier -- implementations usually special-case
the overloading resolution for operator symbols, since they are so
heavily overloaded.  Maybe the fact that all predefined functions
are operators simplifies that.  Not a big deal, but it does have
a certain uniformity -- e.g. "not" is an operator symbol, too,
and works the same way as "abs".

> Is there no way to write a function abs() that, say, computes the
> absolute value of each of the components of a float array?

As others have pointed out, you can write a such an "abs" function.

If you want to call it like this:

    abs(X)

that's fine.

- Bob



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

* Re: Why is abs an operator, not a function?
  2006-10-19  1:45 ` Robert A Duff
@ 2006-10-19  4:30   ` Keith Thompson
  0 siblings, 0 replies; 6+ messages in thread
From: Keith Thompson @ 2006-10-19  4:30 UTC (permalink / raw)


Robert A Duff <bobduff@shell01.TheWorld.com> writes:
> "Jerry" <lanceboyle@qwest.net> writes:
>> Why is abs an operator and not a function? Just wondering.
>
> An operator _is_ a function.  So the question really is, why is the name
> of the abs function an operator symbol (a reserved word) rather than an
> identifier?
>
> In early (pre-1983) versions of Ada, Abs was not an operator -- just a
> normal function with identifier Abs as its name.  I think it was changed
> to make implementations easier -- implementations usually special-case
> the overloading resolution for operator symbols, since they are so
> heavily overloaded.  Maybe the fact that all predefined functions
> are operators simplifies that.  Not a big deal, but it does have
> a certain uniformity -- e.g. "not" is an operator symbol, too,
> and works the same way as "abs".

And for the sake of uniformity, if Abs weren't an operator, it would
probably be an attribute.  (It *could* be a normal function, declared
implicitly for each numeric type, as it was pre-1983, but it would be
the only one.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.



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

* Re: Why is abs an operator, not a function?
  2006-10-18  5:13 Why is abs an operator, not a function? Jerry
                   ` (2 preceding siblings ...)
  2006-10-19  1:45 ` Robert A Duff
@ 2006-10-23  2:39 ` Jerry
  3 siblings, 0 replies; 6+ messages in thread
From: Jerry @ 2006-10-23  2:39 UTC (permalink / raw)



Jerry wrote:
> Why is abs an operator and not a function? Just wondering.
>
> Is there no way to write a function abs() that, say, computes the
> absolute value of each of the components of a float array?
> 
> Jerry

Thanks for the comments, everyone.

Jerry




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

end of thread, other threads:[~2006-10-23  2:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-18  5:13 Why is abs an operator, not a function? Jerry
2006-10-18  7:30 ` Dmitry A. Kazakov
2006-10-18  7:36 ` Samuel Tardieu
2006-10-19  1:45 ` Robert A Duff
2006-10-19  4:30   ` Keith Thompson
2006-10-23  2:39 ` Jerry

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