comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Ada202X : Adding functors
Date: Fri, 16 Nov 2012 11:12:49 +0100
Date: 2012-11-16T11:12:47+01:00	[thread overview]
Message-ID: <50a6119f$0$9519$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <BLydnSqRNdU4GDjNRVn_vwA@giganews.com>

On 16.11.12 01:15, Peter C. Chapin wrote:
> val resultList = filter(myList, _ % 2 == 0)

Incidentally, I have just again had to turn a short expression
like this into a regular function, since keeping it as an
expression would have made the program unreadable.

I think that "growing up" to become a function is the fate of many
expressions playing the role of a function.

In the language I need to use, filtering looks like

   my @resultList = grep { _ % 2 == 0 } @$myList;

Actually, I also need to sort records in $myList in reverse order by
a field named "id". Language support is structurally similar to
filtering. Special sort variables $a and $b provided by the language:

   my @resultList = sort { $b->{"id"} <=> $a->{"id"} } @$myList;

Again, an unnamed expression, $b->{"id"} <=> $a->{"id"}.

It turned out at some point that the components of $myList needed a
more complex comparison, since "id" would not establish the desired
order. Therefore, the statement now is,

   my @resultList = sort $by_latest @$myList;

where $by_latest is a code reference, a "function pointer".  But! As
almost always, the function would not need to carry its environment
around.

So the situation made me end up with the Perl equivalent of a plain
old Ada generic or function pointer, roughly,

   generic
      type T(<>) is private;
      with Comp (a, b: T) return int;
      -- ...
   function sort (items : in out List) return List;

This is not the first time that an expression had to become a function.
To me, this development seems to be the more frequent case.

Maybe unnamed expressions work much better in the role of a gimmick,
for example, when introducing "generic functions" by demonstration.




  reply	other threads:[~2012-11-16 10:12 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-12 22:09 Ada202X : Adding functors Martin
2012-11-12 23:14 ` Jeffrey Carter
2012-11-12 23:19   ` Martin
2012-11-13 10:45     ` Georg Bauhaus
2012-11-13 12:08       ` Yannick Duchêne (Hibou57)
2012-11-13 12:35       ` Martin
2012-11-12 23:44 ` Adam Beneschan
2012-11-13  2:11   ` Jeffrey Carter
2012-11-13 11:11   ` Martin
2012-11-14  0:51     ` Adam Beneschan
2012-11-14  8:39       ` Martin
2012-11-14 16:54         ` Adam Beneschan
2012-11-14 18:54           ` Martin
2012-11-14 20:37           ` Dmitry A. Kazakov
2012-11-14 20:57             ` Shark8
2012-11-14 21:31             ` Martin
2012-11-14 22:42               ` Adam Beneschan
2012-11-15  9:27               ` Dmitry A. Kazakov
2012-11-14 21:45             ` Simon Wright
2012-11-14 22:22               ` Martin
2012-11-14 22:27               ` Martin
2012-11-13  4:22 ` Shark8
2012-11-15  0:20 ` sbelmont700
2012-11-15  7:12   ` Martin
2012-11-15 12:21     ` Georg Bauhaus
2012-11-15 12:31     ` Georg Bauhaus
2012-11-15 12:46       ` Martin
2012-11-16  6:15       ` Randy Brukardt
2012-11-15 10:11   ` Dmitry A. Kazakov
2012-11-15 15:52     ` Peter C. Chapin
2012-11-15 17:04       ` Dmitry A. Kazakov
2012-11-15 19:57         ` Georg Bauhaus
2012-11-15 20:39           ` Dmitry A. Kazakov
2012-11-16  0:15             ` Peter C. Chapin
2012-11-16 10:12               ` Georg Bauhaus [this message]
2012-11-16  0:01         ` Peter C. Chapin
2012-11-16  6:09           ` Randy Brukardt
2012-11-16 12:35             ` Peter C. Chapin
2012-11-16 18:10               ` Martin
2012-11-16  8:59           ` Dmitry A. Kazakov
2012-11-16 12:20             ` Peter C. Chapin
2012-11-16 17:44               ` Dmitry A. Kazakov
2012-11-18 15:58                 ` Peter C. Chapin
2012-11-15 21:34     ` sbelmont700
replies disabled

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