comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Vector of Vectors.
Date: Mon, 19 Jan 2009 12:52:33 +0100
Date: 2009-01-19T12:52:33+01:00	[thread overview]
Message-ID: <49746981$0$30231$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <wccfxjgti9o.fsf@shell01.TheWorld.com>

Robert A Duff schrieb:
> Georg Bauhaus <see.reply.to@maps.futureapps.de> writes:
> 
>> Robert A Duff wrote:
>>
>>> The loop body is usually self explanatory.  E.g:
>> I wish it were, yes. A loop body _should_ be
>> elf explanatory.  FWIW, I have not seen a loop
>> with just single statement in quite a while.
>> Hope things are in different shape elsewhere.
> 
> Not sure what you mean.  I'm saying that Ada's current support for
> iterators requires you to wrap the loop body in a named procedure.
> The fact that people don't normally wrap loop bodies in procedures
> (when using 'for' and 'while' loops) proves that doing so is a burden.

But the fact that people don't normally bother to wrap loop bodies in
procedures is not a prove that to do must be wrong, or that giving
a loop name might not in fact be preferrable.  Yes, it is work to
find a good name but OTOH, it is considered good style, in particular
in Ada culture, to Say What You Mean. AFAIK.

I agree that the example you have given might show
some silly formalism. But again, is this a typical
scenario warranting more anonymity in Ada?

Eiffel's new anonymous agents (access sub parameters with
partially bound arguments) have met some criticism, too, BTW.

Here is another example, one active and one passive
iteration.  Does the loop body deserve a captivating
title?  Then, maybe in the form of a named local procedure.


   function Active (Data: Vector; Threshold: Amount) return Amount is

      N: Positive;                      -- nth item
      Result: Amount;
      Item: Amount;

   begin
      Result := 0.0;
      N := 1;
      for Index in First_Index(Data) .. Last_Index(Data) loop
         Item := Element(Data, Index);
         if Item < Threshold then
            Result := ((N - 1) * Result + Item) / N;
            N := N + 1;
         else
            Skipped := Skipped + 1;
         end if;
      end loop;
      return Result;
   end Active;



   function Passive (Data: Vector; Threshold: Amount) return Amount is

      N: Positive;                      -- nth item
      Result: Amount;

      procedure Incremental_Average(Position: in Cursor) is
         Item: constant Amount := Element(Position);
      begin
         if Item < Threshold then
            Result := ((N - 1) * Result + Item) / N;
            N := N + 1;
         else
            Skipped := Skipped + 1;
         end if;
      end Incremental_Average;

   begin
      Result := 0.0;
      N := 1;
      Iterate(Data, Process => Incremental_Average'Access);
      return Result;
   end Passive;



In Active, the new syntax you have suggested will shorten
the loop body a bit, making Item's declaration in Active's
declarative part unneccesary.  But still, there will be a
few lines left, worth a comment, at least?  If so,
then why not write a named body?


Writing quick, anonymous, non-recursive lamdas is fun,
but there is inherent danger in making them a language
feature, I think.  The danger is that they are going to
be used like they are being used in Python, or
Perl:  spanning multiple lines, trying to be clever,
avoid finding a name, write them once, never understand
them again.

See also the proliferation of anonymous access  ;-)
(I recall Vdim Gunko (I think) saying that adding named 'class
pointers to the Qt4 (C++) binding is too much of a burdon...



  reply	other threads:[~2009-01-19 11:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-15  0:32 Vector of Vectors Peter C. Chapin
2009-01-15  2:44 ` Jeffrey R. Carter
2009-01-15 10:10   ` Alex R. Mosteo
2009-01-15 10:56     ` Georg Bauhaus
2009-01-15 20:44     ` Jeffrey R. Carter
2009-01-15 21:26       ` Robert A Duff
2009-01-17 10:20         ` Ivan Levashew
2009-01-17 10:51           ` Dmitry A. Kazakov
2009-01-17 16:45             ` Robert A Duff
2009-01-17 17:18               ` Dmitry A. Kazakov
2009-01-17 23:06                 ` Robert A Duff
2009-01-18  9:44                   ` Dmitry A. Kazakov
2009-01-17 16:41           ` Robert A Duff
2009-01-17 18:56             ` Georg Bauhaus
2009-01-17 22:59               ` Robert A Duff
2009-01-18 18:34                 ` Georg Bauhaus
2009-01-18 21:29                   ` Robert A Duff
2009-01-19 11:52                     ` Georg Bauhaus [this message]
2009-01-19 12:39                       ` Georg Bauhaus
2009-01-20  2:11                     ` Randy Brukardt
2009-01-15 12:08   ` Peter C. Chapin
2009-01-16 10:15     ` Alex R. Mosteo
replies disabled

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