comp.lang.ada
 help / color / mirror / Atom feed
* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 How to make like Fortran "do i = 1,20,2" Reinert Korsnes
                   ` (2 preceding siblings ...)
  2000-07-27  0:00 ` Larry Kilgallen
@ 2000-07-27  0:00 ` Lutz Donnerhacke
  2000-07-27  0:00 ` G. de Montmollin
  4 siblings, 0 replies; 22+ messages in thread
From: Lutz Donnerhacke @ 2000-07-27  0:00 UTC (permalink / raw)


* Reinert Korsnes wrote:
>How can one in Ada elegantly make a loop through each 2 element of an
>array ? I am looking for something like: "do i = 1,20,2" in Fortran,

-- Not tested
for J in 0 .. A'Length/2 loop
   declare
      I : constant Integer = 2*J + A'First;
   begin
      something...
   end;
end loop;




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 How to make like Fortran "do i = 1,20,2" Reinert Korsnes
  2000-07-27  0:00 ` des walker
  2000-07-27  0:00 ` Ken Garlington
@ 2000-07-27  0:00 ` Larry Kilgallen
  2000-07-27  0:00   ` Gary Scott
  2000-07-27  0:00 ` Lutz Donnerhacke
  2000-07-27  0:00 ` G. de Montmollin
  4 siblings, 1 reply; 22+ messages in thread
From: Larry Kilgallen @ 2000-07-27  0:00 UTC (permalink / raw)


In article <8lpcbe$40n$1@news.uit.no>, reinert@ola.npolar.no (Reinert Korsnes) writes:
> 
> Hi,
> 
> How can one in Ada elegantly make a loop through each 2 element of an array ?  
> I am looking for something like: "do i = 1,20,2" in Fortran, or
> 
> for I in A'range ("step 2") loop
>    something...
> end loop;

===========

for I in A'range loop
    if (I - A'first) mod 2 = 0
    then
        null;
    end if;
end loop;

But of course that does nothing to ensure that A'length is an even number.

===========

for I2 in A'first/2 .. A'last/2 loop
    declare
        I : INTEGER := I2*2;
    begin
        null;
    end;
end loop;

That approach will have problems if either A'length is an odd
number or if either limit of A'range is an odd number.

===========

But what does Fortran do in those negative and odd number cases ?




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 How to make like Fortran "do i = 1,20,2" Reinert Korsnes
                   ` (3 preceding siblings ...)
  2000-07-27  0:00 ` Lutz Donnerhacke
@ 2000-07-27  0:00 ` G. de Montmollin
  4 siblings, 0 replies; 22+ messages in thread
From: G. de Montmollin @ 2000-07-27  0:00 UTC (permalink / raw)


Reinert Korsnes:

> Yes, I can use:

> I := A'first;
> while I <= A'Last loop;
>   something..
>   I := I + 2;
> end loop;

> But this does not look so elegant....

More elegant but also efficient and readable (without
"/", "*" or "MOD" tricks): I fear there isn't. Maybe a
reason why "they" didn't add a "step N" is that A'Last is
not necessarily reached - I guess, a security issue...

______________________________________________________
Gautier  --  http://members.xoom.com/gdemont/gsoft.htm




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 How to make like Fortran "do i = 1,20,2" Reinert Korsnes
@ 2000-07-27  0:00 ` des walker
  2000-07-27  0:00   ` Gary Scott
  2000-07-27  0:00   ` tmoran
  2000-07-27  0:00 ` Ken Garlington
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 22+ messages in thread
From: des walker @ 2000-07-27  0:00 UTC (permalink / raw)


Reinert Korsnes wrote:

> Hi,
>
> How can one in Ada elegantly make a loop through each 2 element of an array ?
> I am looking for something like: "do i = 1,20,2" in Fortran, or
>
> for I in A'range ("step 2") loop
>    something...
> end loop;
>
> Yes, I can use:
>
> I := A'first;
> while I <= A'Last loop;
>   something..
>   I := I + 2;
> end loop;
>
> But this does not look so elegant....
>
> reinert
>
> --
> Norwegian Polar Institute
> Polar Environment Center
> N-9296 Tromso
> Norway
> Fax: +47 77750501
>
> http://geophys.npolar.no/~reinert/personal.html

Often wanting to process data in this manner would suggest that there might be a
more meaningful way to express the structure of the data. A lot of effort can be
spent in Ada designing good data types which makes it simple to write safe code.

If the two element blocks of your array hold, say, a coordinate pair you might
have

type coordinate is record
  X,Y : integer;
end record;

type coordinate_array is array(Natural range <>) of coordinate;

then processing the array reduces to

procedure Process_Array(The_Array : in coordinate_array) is
begin
  for I in The_Array'first .. The_Array'last loop
    Do_Something(The_Array(I));
  end loop;
end Process_Array;

Now the elegance is returned to the loop block.
An earlier respondent also mentioned that there is no guarantee that your
original array is an even number of elements long, here the problem is neatly
avoided because the array will consist of complete elements.

I realise that it is not always possible to backtrack on data structures that are
already defined, but Data Abstraction in Ada is a good tool for writing safe,
extensible code.

    Des
    Alenia-Marconi Systems






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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 ` Larry Kilgallen
@ 2000-07-27  0:00   ` Gary Scott
  2000-07-27  0:00     ` Larry Kilgallen
                       ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Gary Scott @ 2000-07-27  0:00 UTC (permalink / raw)


Hmmm, these and similar examples posted do not make Ada look very
elegant...it makes a very simple concept seem somewhat convoluted.

Larry Kilgallen wrote:
> 
> In article <8lpcbe$40n$1@news.uit.no>, reinert@ola.npolar.no (Reinert Korsnes) writes:
> >
> > Hi,
> >
> > How can one in Ada elegantly make a loop through each 2 element of an array ?
> > I am looking for something like: "do i = 1,20,2" in Fortran, or
> >
> > for I in A'range ("step 2") loop
> >    something...
> > end loop;
> 
> ===========
> 
> for I in A'range loop
>     if (I - A'first) mod 2 = 0
>     then
>         null;
>     end if;
> end loop;
> 
> But of course that does nothing to ensure that A'length is an even number.
> 
> ===========
> 
> for I2 in A'first/2 .. A'last/2 loop
>     declare
>         I : INTEGER := I2*2;
>     begin
>         null;
>     end;
> end loop;
> 
> That approach will have problems if either A'length is an odd
> number or if either limit of A'range is an odd number.
> 
> ===========
> 
> But what does Fortran do in those negative and odd number cases ?




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00   ` Gary Scott
  2000-07-27  0:00     ` Larry Kilgallen
@ 2000-07-27  0:00     ` Pat Rogers
  2000-07-27  0:00     ` Matthew J Heaney
  2000-07-27  0:00     ` mjsilva
  3 siblings, 0 replies; 22+ messages in thread
From: Pat Rogers @ 2000-07-27  0:00 UTC (permalink / raw)


"Gary Scott" <Gary.L.Scott@lmtas.lmco.com> wrote in message
news:39805669.3E7CF6CF@lmtas.lmco.com...
> Hmmm, these and similar examples posted do not make Ada look very
> elegant...it makes a very simple concept seem somewhat convoluted.

To quote the Ada 83 Rationale:

"Several studies on the use of programming languages have shown that
the vast majority of loops are very simple.  Hence generalities such
as the step expression of Algol 60 should be avoided."

Like it or not (and I don't), that was the stated justification.


--
Pat Rogers                            Consulting and Training in:
http://www.classwide.com      Deadline Schedulability Analysis
progers@classwide.com        Software Fault Tolerance
(281)648-3165                       Real-Time/OO Languages

Adam ... does not deserve all the credit; much is due to Eve, the
first woman, and Satan, the first consultant.
Mark Twain







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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 ` des walker
  2000-07-27  0:00   ` Gary Scott
@ 2000-07-27  0:00   ` tmoran
  2000-07-28  0:00     ` Reinert Korsnes
  1 sibling, 1 reply; 22+ messages in thread
From: tmoran @ 2000-07-27  0:00 UTC (permalink / raw)


>Often wanting to process data in this manner would suggest that there
>might be a more meaningful way to express the structure of the data.
  Amen! In my experience, if Ada makes it hard to code something one
way, some thought will almost always show that it could be expressed
more elegantly and more clearly in another way.
  Why in this case do you want to step by 2's through the array?




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00   ` Gary Scott
                       ` (2 preceding siblings ...)
  2000-07-27  0:00     ` Matthew J Heaney
@ 2000-07-27  0:00     ` mjsilva
  3 siblings, 0 replies; 22+ messages in thread
From: mjsilva @ 2000-07-27  0:00 UTC (permalink / raw)


I'd say that it's the required looping conditions that are somewhat
convoluted.  Acting only on every Nth element is much, much less common
than acting on every element (I honestly can't remember the last time I
needed to do this), so perhaps more explicit coding for this case is
not only acceptable but even desirable.

Mike

In article <39805669.3E7CF6CF@lmtas.lmco.com>,
  Gary Scott <Gary.L.Scott@lmtas.lmco.com> wrote:
> Hmmm, these and similar examples posted do not make Ada look very
> elegant...it makes a very simple concept seem somewhat convoluted.
>
> Larry Kilgallen wrote:
> >
> > In article <8lpcbe$40n$1@news.uit.no>, reinert@ola.npolar.no
(Reinert Korsnes) writes:
> > >
> > > Hi,
> > >
> > > How can one in Ada elegantly make a loop through each 2 element
of an array ?
> > > I am looking for something like: "do i = 1,20,2" in Fortran, or
> > >
> > > for I in A'range ("step 2") loop
> > >    something...
> > > end loop;
> >
> > ===========
> >
> > for I in A'range loop
> >     if (I - A'first) mod 2 = 0
> >     then
> >         null;
> >     end if;
> > end loop;
> >
> > But of course that does nothing to ensure that A'length is an even
number.
> >
> > ===========
> >
> > for I2 in A'first/2 .. A'last/2 loop
> >     declare
> >         I : INTEGER := I2*2;
> >     begin
> >         null;
> >     end;
> > end loop;
> >
> > That approach will have problems if either A'length is an odd
> > number or if either limit of A'range is an odd number.
> >
> > ===========
> >
> > But what does Fortran do in those negative and odd number cases ?
>


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00   ` Gary Scott
@ 2000-07-27  0:00     ` Larry Kilgallen
  2000-07-27  0:00     ` Pat Rogers
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 22+ messages in thread
From: Larry Kilgallen @ 2000-07-27  0:00 UTC (permalink / raw)


In article <39805669.3E7CF6CF@lmtas.lmco.com>, Gary Scott <Gary.L.Scott@lmtas.lmco.com> writes:
> Hmmm, these and similar examples posted do not make Ada look very
> elegant...it makes a very simple concept seem somewhat convoluted.
> 
> Larry Kilgallen wrote:

Well _mine_ may have looked convoluted, but the one from Des Walker
was spot on.

The original Fortran was dealing with groups of two but not grouping
them and instead coding a solution more like machine language.  It is
possible to write Fortran in Ada, but you shouldn't.

> Often wanting to process data in this manner would suggest that there
> might be a more meaningful way to express the structure of the data.
> A lot of effort can be spent in Ada designing good data types which
> makes it simple to write safe code.
> 
> If the two element blocks of your array hold, say, a coordinate pair
> you might have
> 
> type coordinate is record
>   X,Y : integer;
> end record;

etc.




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 How to make like Fortran "do i = 1,20,2" Reinert Korsnes
  2000-07-27  0:00 ` des walker
@ 2000-07-27  0:00 ` Ken Garlington
  2000-07-27  0:00 ` Larry Kilgallen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 22+ messages in thread
From: Ken Garlington @ 2000-07-27  0:00 UTC (permalink / raw)



"Reinert Korsnes" <reinert@ola.npolar.no> wrote in message
news:8lpcbe$40n$1@news.uit.no...
>
> Hi,
>
> How can one in Ada elegantly make a loop through each 2 element of an
array ?
> I am looking for something like: "do i = 1,20,2" in Fortran, or
>
> for I in A'range ("step 2") loop
>    something...
> end loop;
>
> Yes, I can use:
>
> I := A'first;
> while I <= A'Last loop;
>   something..
>   I := I + 2;
> end loop;
>
> But this does not look so elegant....

Just off the top of my head:

for I in Beginning_Selection .. Final_Selection loop

   something involving A(Selected_By(I));

end loop;

where the functions come from a generic with a Step constant and an array
index type as parameters, with functions sketched as

  Beginning_Selection: Type'First;
  Final_Selection: Type'First + (Type'Length/Step) - 1 -- depends upon what
you want to do with odd-valued arrays, etc.
  Selected_By(I): I * Step;







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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00 ` des walker
@ 2000-07-27  0:00   ` Gary Scott
  2000-07-27  0:00   ` tmoran
  1 sibling, 0 replies; 22+ messages in thread
From: Gary Scott @ 2000-07-27  0:00 UTC (permalink / raw)


You can also design this same abstraction in Fortran if you like and for
something like initialization of a whole array or section, it could be
reduced to a single statement.

des walker wrote:
> 
> Reinert Korsnes wrote:
> 
> > Hi,
> >
> > How can one in Ada elegantly make a loop through each 2 element of an array ?
> > I am looking for something like: "do i = 1,20,2" in Fortran, or
> >
> > for I in A'range ("step 2") loop
> >    something...
> > end loop;
> >
> > Yes, I can use:
> >
> > I := A'first;
> > while I <= A'Last loop;
> >   something..
> >   I := I + 2;
> > end loop;
> >
> > But this does not look so elegant....
> >
> > reinert
> >
> > --
> > Norwegian Polar Institute
> > Polar Environment Center
> > N-9296 Tromso
> > Norway
> > Fax: +47 77750501
> >
> > http://geophys.npolar.no/~reinert/personal.html
> 
> Often wanting to process data in this manner would suggest that there might be a
> more meaningful way to express the structure of the data. A lot of effort can be
> spent in Ada designing good data types which makes it simple to write safe code.
> 
> If the two element blocks of your array hold, say, a coordinate pair you might
> have
> 
> type coordinate is record
>   X,Y : integer;
> end record;
> 
> type coordinate_array is array(Natural range <>) of coordinate;
> 
> then processing the array reduces to
> 
> procedure Process_Array(The_Array : in coordinate_array) is
> begin
>   for I in The_Array'first .. The_Array'last loop
>     Do_Something(The_Array(I));
>   end loop;
> end Process_Array;
> 
> Now the elegance is returned to the loop block.
> An earlier respondent also mentioned that there is no guarantee that your
> original array is an even number of elements long, here the problem is neatly
> avoided because the array will consist of complete elements.
> 
> I realise that it is not always possible to backtrack on data structures that are
> already defined, but Data Abstraction in Ada is a good tool for writing safe,
> extensible code.
> 
>     Des
>     Alenia-Marconi Systems




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00   ` Gary Scott
  2000-07-27  0:00     ` Larry Kilgallen
  2000-07-27  0:00     ` Pat Rogers
@ 2000-07-27  0:00     ` Matthew J Heaney
  2000-07-28  0:00       ` Gary Scott
  2000-07-27  0:00     ` mjsilva
  3 siblings, 1 reply; 22+ messages in thread
From: Matthew J Heaney @ 2000-07-27  0:00 UTC (permalink / raw)


Gary Scott <Gary.L.Scott@lmtas.lmco.com> writes:

> Hmmm, these and similar examples posted do not make Ada look very
> elegant...it makes a very simple concept seem somewhat convoluted.

This "very simple concept" is a major source of bugs -- that's why it's
not in the language.

If you want to increment by 2 through the loop, it's simple enough:

declare
   I : Positive := A'First;
begin
   while I <= A'Last loop
      ... A(I) ...
      I := I + 2;
   end loop;
end;

QED


If you want to do odd-ball things, then sometimes that requires extra
work.  The common things (like incrementing the loop index by 1) are
easy to do.

I can't even remember the last time I had to iterate over an array by an
increment other than 1.

Consider this analogy.  Suppose you want to iterate over a linked list:

   list<int> intList;
...
   list<int>::iterator iter = intList.begin();

In the normal case, when you increment by 1, it's simple:

   while (iter != intList.end())
   {
     ...
     iter++;
   }


Asking how to iterate in increments of 2 is like asking, How do I visit
every other list element?  That's an odd-ball thing to do, so you have
to do extra work.  (Try it and you'll see.)









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

* How to make like Fortran "do i = 1,20,2"
@ 2000-07-27  0:00 Reinert Korsnes
  2000-07-27  0:00 ` des walker
                   ` (4 more replies)
  0 siblings, 5 replies; 22+ messages in thread
From: Reinert Korsnes @ 2000-07-27  0:00 UTC (permalink / raw)



Hi,

How can one in Ada elegantly make a loop through each 2 element of an array ?  
I am looking for something like: "do i = 1,20,2" in Fortran, or

for I in A'range ("step 2") loop
   something...
end loop;

Yes, I can use:

I := A'first;
while I <= A'Last loop;
  something..
  I := I + 2;
end loop;

But this does not look so elegant....

reinert

-- 
Norwegian Polar Institute
Polar Environment Center
N-9296 Tromso
Norway
Fax: +47 77750501

http://geophys.npolar.no/~reinert/personal.html




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-28  0:00     ` Reinert Korsnes
@ 2000-07-28  0:00       ` Gautier
  2000-07-29  0:00       ` tmoran
  1 sibling, 0 replies; 22+ messages in thread
From: Gautier @ 2000-07-28  0:00 UTC (permalink / raw)


Reinert Korsnes:

> OK, I've learned a lesson.  I tried a "hack"....  No excuses hereby expressed.
> 
> But when one mixes languages one may have to visit each N'te element in
> arrays.  But this may not be really Ada....
> 
> When one tries to deal with representing geometry and solve
> differential equations and following some mathematical
> notation, one may want to visit subsets of elements in arrays ?
> (Though, those examples may be odd and based on "thinking Fortran"....).

The cases of arrays that must be stepped by various step sizes
appear almost never (or never at all) in my number-crunchings - even
with a lot of tables, re-indexings, multi-equation finite elements
and so on. It means that defining records for pairs, indexing with
enumeration types for various options etc. becomes a "reflexe" of
Ada programming.
You enrich the meaning of source code, for you and the compiler's
optimiser, and you avoid typical bad surprises where you add
a third case and forget changing a step somewhere, or swap
(in mind) from 2*N to N*2...

______________________________________________________
Gautier  --  http://members.xoom.com/gdemont/gsoft.htm




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00     ` Matthew J Heaney
@ 2000-07-28  0:00       ` Gary Scott
  2000-07-28  0:00         ` mjsilva
  2000-07-29  0:00         ` Ehud Lamm
  0 siblings, 2 replies; 22+ messages in thread
From: Gary Scott @ 2000-07-28  0:00 UTC (permalink / raw)




Matthew J Heaney wrote:
> 
> Gary Scott <Gary.L.Scott@lmtas.lmco.com> writes:
> 
> > Hmmm, these and similar examples posted do not make Ada look very
> > elegant...it makes a very simple concept seem somewhat convoluted.
> 
> This "very simple concept" is a major source of bugs -- that's why it's
> not in the language.

"Studies" of language usage and error inducing constructs can be made to
support virtually any preconceived notion.  I'm more interested in
producing the code that solves a particular problem in the easiest to
understand and straightforward form rather than in the most elegant in
terms of abstraction.  Of course it is very common to use steps in
languages with somewhat limited alternative constructs in certain
circumstances when the problem might be solved in another way more
clearly and/or elegantly.  Fortran 95 supports all of the alternative
methods presented so far in addition to the single DO-STEP construct.

> 
> If you want to increment by 2 through the loop, it's simple enough:
> 
> declare
>    I : Positive := A'First;
> begin
>    while I <= A'Last loop
>       ... A(I) ...
>       I := I + 2;
>    end loop;
> end;
> 
> QED
> 
> If you want to do odd-ball things, then sometimes that requires extra
> work.  The common things (like incrementing the loop index by 1) are
> easy to do.
> 
> I can't even remember the last time I had to iterate over an array by an
> increment other than 1.
> 
> Consider this analogy.  Suppose you want to iterate over a linked list:
> 
>    list<int> intList;
> ...
>    list<int>::iterator iter = intList.begin();
> 
> In the normal case, when you increment by 1, it's simple:
> 
>    while (iter != intList.end())
>    {
>      ...
>      iter++;
>    }
> 
> Asking how to iterate in increments of 2 is like asking, How do I visit
> every other list element?  That's an odd-ball thing to do, so you have
> to do extra work.  (Try it and you'll see.)




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-28  0:00       ` Gary Scott
@ 2000-07-28  0:00         ` mjsilva
  2000-07-29  0:00         ` Ehud Lamm
  1 sibling, 0 replies; 22+ messages in thread
From: mjsilva @ 2000-07-28  0:00 UTC (permalink / raw)


In article <3981A390.A1F3D127@lmtas.lmco.com>,
  Gary Scott <Gary.L.Scott@lmtas.lmco.com> wrote:
>
>
> Matthew J Heaney wrote:
> >
> > Gary Scott <Gary.L.Scott@lmtas.lmco.com> writes:
> >
> > > Hmmm, these and similar examples posted do not make Ada look very
> > > elegant...it makes a very simple concept seem somewhat convoluted.
> >
> > This "very simple concept" is a major source of bugs -- that's why
it's
> > not in the language.
>
> "Studies" of language usage and error inducing constructs can be made
to
> support virtually any preconceived notion.  I'm more interested in
> producing the code that solves a particular problem in the easiest to
> understand and straightforward form rather than in the most elegant in
> terms of abstraction.  Of course it is very common...

I don't think there's any concensus that this is the case.  Just for
grins I checked my current project (in C) and found 241 "for" loops.
Not a single one had a step size other than 1.  OTOH, each of those 241
loops would have a much more elegant form in Ada...

>...to use steps in
> languages with somewhat limited alternative constructs in certain
> circumstances when the problem might be solved in another way more
> clearly and/or elegantly.  Fortran 95 supports all of the alternative
> methods presented so far in addition to the single DO-STEP construct.

Out of curiosity does Fortran 95 have the equivalent of Ada's various
implicit loop bounds (I in X'range, I in X'first..X'last, I in X_type)?

Mike



Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-27  0:00   ` tmoran
@ 2000-07-28  0:00     ` Reinert Korsnes
  2000-07-28  0:00       ` Gautier
  2000-07-29  0:00       ` tmoran
  0 siblings, 2 replies; 22+ messages in thread
From: Reinert Korsnes @ 2000-07-28  0:00 UTC (permalink / raw)


In article <aa1g5.67$bT6.41853@news.pacbell.net>,
 tmoran@bix.com writes:
>>Often wanting to process data in this manner would suggest that there
>>might be a more meaningful way to express the structure of the data.
>  Amen! In my experience, if Ada makes it hard to code something one
>way, some thought will almost always show that it could be expressed
>more elegantly and more clearly in another way.
>  Why in this case do you want to step by 2's through the array?


OK, I've learned a lesson.  I tried a "hack"....  No excuses hereby expressed.

But when one mixes languages one may have to visit each N'te element in
arrays.  But this may not be really Ada....

When one tries to deal with representing geometry and solve
differential equations and following some mathematical
notation, one may want to visit subsets of elements in arrays ?
(Though, those examples may be odd and based on "thinking Fortran"....).

reinert


-- 
Norwegian Polar Institute
Polar Environment Center
N-9296 Tromso
Norway
Fax: +47 77750501

http://geophys.npolar.no/~reinert/personal.html




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-29  0:00         ` Ehud Lamm
@ 2000-07-28  0:00           ` Richard Riehle
       [not found]           ` <39833637.3B83BFAC@lmtas.lmco.com>
  2000-07-29  0:00           ` Robert I. Eachus
  2 siblings, 0 replies; 22+ messages in thread
From: Richard Riehle @ 2000-07-28  0:00 UTC (permalink / raw)




Ehud Lamm wrote:

> One of the nice things about programming is that you can choose from
> different languages. If you find Ada a bad languaged - use something else!
>
> I usually find myself in agreement with the desginers of Ada. Sometimes
> though, reaching this conclusion takes time and refelction.

Ehud has a good point.  However, I would soften it somewhat and suggest that
it is
not a matter of good or bad.   Rather, it is an issue of expressiveness versus
expressibility.

Some languages are more expressive of a given feature than others.   In Ada we
can easily
design a for loop that includes a step feature, but Fortran (along with BASIC
and other
languages) is more directly expressive of that capability than Ada.   We had a
debate in
another thread about assertions (pre-, post-, and invariants).   Some
development tools, such as
Eiffel and the Spark Examiner for Ada, are more expressive of this notion than
standard Ada.
A couple of years ago I posted a challenge for the design of a package
specification that would
directly express the powerful EVALUATE verb of ANSI-1985 COBOL using Ada.  No
one
really came very close using Ada.  There were some creative efforts, but none
had the expressive
power of COBOL.   To be fair, no one seems able to accomplish this in Eiffel
or C++ any more
effectively.

Ultimately, we can express any construct in nearly any language.   That is not
the point.  Expressible
is not the same as expressive.    We can, as another example, express opaque
types more conveniently
in Modula-3 than in any of the languages so far named.     At the same time,
Modula-3 typing, using
structural equivalence, is weaker than that in Ada, and even weaker than
current ISO/ANSI C++,
both of which use name equivalence.

Good or bad is not a sufficient level of granularity for making decisions
about languages.   We can easily
prove that one language or another is able to better designed to express a
particular solution model than
any of its competitors.   If one insists on comparing languages on the basis
of a single set of features,
any language can be made to look better than its alternatives.

Ehud makes a good point when he notes that he usually finds himself  "in
agreement with the desginers of Ada."
To really make the decision regarding a programming language choice, when only
one choice is allowed,
suggests that the evaluation be made at a level of abstraction considerably
higher than that of feature selection.
The features help implement the philosophy of the language, but the full
design of the language, including its
consistency, readability, and expressiveness of essential constructs are but a
few of those issues that loom
larger than specific features.

Richard Riehle





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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-28  0:00       ` Gary Scott
  2000-07-28  0:00         ` mjsilva
@ 2000-07-29  0:00         ` Ehud Lamm
  2000-07-28  0:00           ` Richard Riehle
                             ` (2 more replies)
  1 sibling, 3 replies; 22+ messages in thread
From: Ehud Lamm @ 2000-07-29  0:00 UTC (permalink / raw)


On Fri, 28 Jul 2000, Gary Scott wrote:

|
|
|Matthew J Heaney wrote:
|> 
|> Gary Scott <Gary.L.Scott@lmtas.lmco.com> writes:
|> 
|> > Hmmm, these and similar examples posted do not make Ada look very
|> > elegant...it makes a very simple concept seem somewhat convoluted.
|> 
|> This "very simpleconcept" is a major source of bugs -- that's why it's
|> not in the language.
|
|"Studies" of language usage and error inducing constructs can be made to
|support virtually any preconceived notion.  I'm more interested in
|producing the code that solves a particular problem in the easiest to
|understand and straightforward form rather than in the most elegant in
|terms of abstraction.  

Flawed studies, in any field, can prove anything you want...

One of the nice things about programming is that you can choose from
different languages. If you find Ada a bad languaged - use something else! 

I usually find myself in agreement with the desginers of Ada. Sometimes
though, reaching this conclusion takes time and refelction.

And remember: freedom of choice entails, of course, the freedom to choose
wrong.

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!






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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-29  0:00         ` Ehud Lamm
  2000-07-28  0:00           ` Richard Riehle
       [not found]           ` <39833637.3B83BFAC@lmtas.lmco.com>
@ 2000-07-29  0:00           ` Robert I. Eachus
  2 siblings, 0 replies; 22+ messages in thread
From: Robert I. Eachus @ 2000-07-29  0:00 UTC (permalink / raw)


Ehud Lamm wrote:

> One of the nice things about programming is that you can choose from
> different languages. If you find Ada a bad language - use something else!
> 
> I usually find myself in agreement with the desginers of Ada. Sometimes
> though, reaching this conclusion takes time and refelction.

   Let's reflect a bit then.  First, as pointed out elsewhere almost all
for
loops in whatever language step by one.  The second most popular loop
index,
but way behind, is minus one.  All other loop indexes in languages where
you
have arbitirary choices used to add up to less than the number that used
-1.

   So if variable step sizes were allowed in Ada they would have been
used
very rarely.  But just coming up with definitions for the feature is
very
problematical.  For example, how many times should the following loops
be
executed (pseudo, but very definitely illegal, Ada):

   for I in 1..12 step 5 loop

   for I in 0.1..1.0 step 0.03 loop

   for I in Character range 'A'..'Z' step 3 loop

   for I in reverse Integer step -Integer'Last loop

   for I in 1..100 loop
     I := I+2;
   end loop;

   I could go on, but you get the picture.  For Algol 68 I bet Robert
Dewar can answer all those questions off the top of his head.  There are
probably readers of this newsgroup that know the answers for most
version of Fortran, and I know the answers for PL/I.  And I bet thatt
least one answer for each language would surprise most of the readers of
this newsgroup.

   My point is not that those languages are bad or wrong.  But the focus
on appropriate data typing in Ada meant that the effort of defining such
rules, reviewing them, implementing them, and learning and teaching them
was better spent on other, more useful features in Ada.  For example,
the ability to constrain one bound of a subtype, or one dimension of an
array would be much
more useful, and in the "spirit" of Ada.  But even there I think that
the
overall cost of adding the feature would not match its benefit.

  (However, if anyone wants to discuss this, as far as I can tell
allowing such constraints only in the type declaration would gain most
of the benefit and not be too disruptive of the current language.  The
problem for arrays only shows
up if you want a constrained dimension before an unconstrained
dimension, since you can declare an unconstrained array of constrained
arrays in Ada, but not the reverse.)




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

* Re: How to make like Fortran "do i = 1,20,2"
  2000-07-28  0:00     ` Reinert Korsnes
  2000-07-28  0:00       ` Gautier
@ 2000-07-29  0:00       ` tmoran
  1 sibling, 0 replies; 22+ messages in thread
From: tmoran @ 2000-07-29  0:00 UTC (permalink / raw)


>When one tries to deal with representing geometry and solve
>differential equations and following some mathematical
>notation, one may want to visit subsets of elements in arrays ?
  Are the subsets inherent and fixed, two sequential items for an x,y
pair for instance, or are they dynamic, arising from the nature of the
algorithm?
  In the first case, as someone suggested, the "Ada way" would be to
make an array of records, or of two-vectors, or simply a two
dimensional array with rows of length two, and step through it from one
row to the next, ie, by one.
  In the second case, if the algorithm calls for stepping by N at a
time, then, as pointed out, that is indeed more easily expressed in
Fortran than in Ada.  It's surely an unusual situation, though.




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

* Re: How to make like Fortran "do i = 1,20,2"
       [not found]           ` <39833637.3B83BFAC@lmtas.lmco.com>
@ 2000-07-29  0:00             ` Gary Scott
  0 siblings, 0 replies; 22+ messages in thread
From: Gary Scott @ 2000-07-29  0:00 UTC (permalink / raw)


I performed a survey of some of my old code and my highest average usage
of DO-STEP was 1.6 percent in an application that required remapping
to/from internal representation to/from an external 8, 11, 16, 24, and
32-bit integer and floating point representation, some values of which
had to be split in odd places across 16-bit words (i.e. an 11 bit value
with 3 bits in one 16-bit word with the remaining bits in the next
16-bit word).  Not saying that I could not have designed the process
better, but what I designed was quite easy and straightforward and thus
not very error prone (IMO).

Gary Scott wrote:
> 
> Hi,
> 
> I'm an Ada supporter.  I'm very discouraged that many companies seem to
> be giving up on Ada in favor of C/C++.  I think that it's very short
> sighted and based upon a misguided, mis-application of object oriented
> design (in at least one case I'm familiar with where the code was
> essentially performance critical device drivers).
> 
> However, I'm also a Fortran 95/2K supporter.  It seems a much better fit
> for most of the engineering work that I do than any competing language.
> Of course there is baggage how can there not be but you don't have to
> use the obsolescent features.  Baggage is being designed out over time
> and I consider the latest standards to be vastly improved.  DO-STEP is
> definitely not part of the baggage, however.
> 
> Ehud Lamm wrote:
> >
> > On Fri, 28 Jul 2000, Gary Scott wrote:
> >
> > |
> > |
> > |Matthew J Heaney wrote:
> > |>
> > |> Gary Scott <Gary.L.Scott@lmtas.lmco.com> writes:
> > |>
> > |> > Hmmm, these and similar examples posted do not make Ada look very
> > |> > elegant...it makes a very simple concept seem somewhat convoluted.
> > |>
> > |> This "very simpleconcept" is a major source of bugs -- that's why it's
> > |> not in the language.
> > |
> > |"Studies" of language usage and error inducing constructs can be made to
> > |support virtually any preconceived notion.  I'm more interested in
> > |producing the code that solves a particular problem in the easiest to
> > |understand and straightforward form rather than in the most elegant in
> > |terms of abstraction.
> >
> > Flawed studies, in any field, can prove anything you want...
> >
> > One of the nice things about programming is that you can choose from
> > different languages. If you find Ada a bad languaged - use something else!
> >
> > I usually find myself in agreement with the desginers of Ada. Sometimes
> > though, reaching this conclusion takes time and refelction.
> >
> > And remember: freedom of choice entails, of course, the freedom to choose
> > wrong.
> >
> > Ehud Lamm mslamm@mscc.huji.ac.il
> > http://purl.oclc.org/NET/ehudlamm <== My home on the web
> > Check it out and subscribe to the E-List- for interesting essays and more!




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

end of thread, other threads:[~2000-07-29  0:00 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-27  0:00 How to make like Fortran "do i = 1,20,2" Reinert Korsnes
2000-07-27  0:00 ` des walker
2000-07-27  0:00   ` Gary Scott
2000-07-27  0:00   ` tmoran
2000-07-28  0:00     ` Reinert Korsnes
2000-07-28  0:00       ` Gautier
2000-07-29  0:00       ` tmoran
2000-07-27  0:00 ` Ken Garlington
2000-07-27  0:00 ` Larry Kilgallen
2000-07-27  0:00   ` Gary Scott
2000-07-27  0:00     ` Larry Kilgallen
2000-07-27  0:00     ` Pat Rogers
2000-07-27  0:00     ` Matthew J Heaney
2000-07-28  0:00       ` Gary Scott
2000-07-28  0:00         ` mjsilva
2000-07-29  0:00         ` Ehud Lamm
2000-07-28  0:00           ` Richard Riehle
     [not found]           ` <39833637.3B83BFAC@lmtas.lmco.com>
2000-07-29  0:00             ` Gary Scott
2000-07-29  0:00           ` Robert I. Eachus
2000-07-27  0:00     ` mjsilva
2000-07-27  0:00 ` Lutz Donnerhacke
2000-07-27  0:00 ` G. de Montmollin

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