Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.java.programmer Subject: Re: Java 8 Lambda binary snapshot Date: Mon, 14 Nov 2011 08:03:46 -0600 Organization: Aioe.org NNTP Server Lines: 56 Message-ID: References: <2244638.2045.1321057203472.JavaMail.geo-discussion-forums@prep8> <0kuvb71v0ie3qtupn8d04q27fer5s0l49u@4ax.com> <4ec000d8$0$293$14726298@news.sunsite.dk> Reply-To: nma@12000.org NNTP-Posting-Host: r3dxhyOQqo8wOMSV7/0mbw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9954 On 11/13/2011 11:39 AM, Arne Vajhøj wrote: > Java 8 lambda: > > import java.util.ArrayList; > import java.util.Collections; > > public class Lambda { > public static void main(String[] args) { > ArrayList lst = new ArrayList(); > lst.add("A"); > lst.add("BB"); > lst.add("CCC"); > Collections.sort(lst, (s1,s2)-> -s1.compareTo(s2)); > for(String s : lst) { > System.out.println(s); > } > } > } > > Arne > ps. I just heard about this Lambda thing ;) This looks like the ability to have, what is called in Mathematica, or may be other functional languages, a pure function, that one can define and use on the fly ? For example, in Mathematica, one can write "Sort[list,p] sorts using the ordering function p. " and is coded like this, for example: In[11]:= Sort[{4,1,3,2,2},#1>#2&] Out[11]= {4,3,2,2,1} where the '&' indicates the end of the function, and #1 means first argument, and #2 mean the second argument. One can also write the pure function more explicit, like this: In[8]:= Sort[{4,1,3,2,2},Function[{x,y},x