From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2078ce7aac45af5b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.197.201 with SMTP id iw9mr1009812pbc.6.1353060768721; Fri, 16 Nov 2012 02:12:48 -0800 (PST) Path: 6ni89336pbd.1!nntp.google.com!news.glorb.com!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 16 Nov 2012 11:12:49 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada202X : Adding functors References: <0114d327-9f9f-4ad2-9281-56331d11a90c@googlegroups.com> <15w6caje3zsh$.t5nqtwoa77x5$.dlg@40tude.net> <50a5492c$0$9523$9b4e6d93@newsspool1.arcor-online.net> In-Reply-To: Message-ID: <50a6119f$0$9519$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 16 Nov 2012 11:12:47 CET NNTP-Posting-Host: 78961738.newsspool1.arcor-online.net X-Trace: DXC=d?3;lbdmbDgeoCI^f\Y]Eaic==]BZ:afn4Fo<]lROoRankgeX?EC@@`@RHBLX;S0JcPCY\c7>ejVhaBLPQ78TOem9= 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.