comp.lang.ada
 help / color / mirror / Atom feed
* assignments using different types
@ 1997-01-28  0:00 David Dessert
  1997-01-28  0:00 ` Christopher Green
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: David Dessert @ 1997-01-28  0:00 UTC (permalink / raw)



I have a question about readability and efficiency of assignments
when using strict types in Ada83.  I'm using the TI-Tartan C40
compiler, which has few Ada95 features.

Example:
   type Distance_Type is new float range 0.0 .. 1000.0;
   type Time_Type is new float range 0.0 .. 10.0;
   type Velocity_Type is new float;

   Distance : Distance_Type := 100.0;
   Time     : Time_Type     := 10.0;
   Velocity : Velocity_Type;

...

   -- A difficult to read, but legal Ada assignment.
   Velocity := Velocity_Type(float(Distance) / float(Time));


Can anyone provide me with suggestions to improve the readability
of the above assignment?  Of course, I'd like efficiency to be
similar to that of using the same type for all the variables.




^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: assignments using different types
@ 1997-01-29  0:00 tmoran
  0 siblings, 0 replies; 10+ messages in thread
From: tmoran @ 1997-01-29  0:00 UTC (permalink / raw)



>   Velocity := Velocity_Type(float(Distance) / float(Time));
>Can anyone provide me with suggestions to improve the readability
>of the above assignment?  Of course, I'd like efficiency to be

  How about creating

function "/"(Distance : in Distance_Type;
             Time     : in Time_Type)
return Velocity_Type is
begin
  return Velocity_Type(float(Distance) / float(Time));
end "/";

  and then you will be able to write

Velocity := Distance / Time;

(Actually, your current statement is quite readable - though tedious
to write.)




^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: assignments using different types
@ 1997-01-30  0:00 Thomas
  0 siblings, 0 replies; 10+ messages in thread
From: Thomas @ 1997-01-30  0:00 UTC (permalink / raw)



--
On  29 Jan 1997 17:34:54 GMT,  tmoran@bix.com wrote ...
 > >   Velocity := Velocity_Type(float(Distance) / float(Time));
 > >Can anyone provide me with suggestions to improve the readability
 > >of the above assignment?  Of course, I'd like efficiency to be
 > 
 >   How about creating
 > 
 > function "/"(Distance : in Distance_Type;
 >              Time     : in Time_Type)
 > return Velocity_Type is
 > begin
 >   return Velocity_Type(float(Distance) / float(Time));
 > end "/";
 > 
 >   and then you will be able to write
 > 
 > Velocity := Distance / Time;
 > 
 > (Actually, your current statement is quite readable - though tedious
 > to write.)
--






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

end of thread, other threads:[~1997-02-10  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-28  0:00 assignments using different types David Dessert
1997-01-28  0:00 ` Christopher Green
1997-01-29  0:00 ` Robert Dewar
1997-01-30  0:00   ` inter-unit inlining (was: Re: assignments using different types) Fergus Henderson
1997-01-29  0:00 ` assignments using different types Robert Dewar
1997-01-29  0:00 ` Robert I. Eachus
1997-01-29  0:00 ` Paul Van Bellinghen
1997-02-10  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1997-01-29  0:00 tmoran
1997-01-30  0:00 Thomas

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