Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: new Java lambda syntax Date: Tue, 13 Sep 2011 21:36:56 -0500 Organization: A noiseless patient Spider Lines: 35 Message-ID: References: <9j3vj8-aqe.ln1@news.simpsonst.f2s.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 14 Sep 2011 02:37:33 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="WpcHJSul77m+zlbR9GVqkA"; logging-data="27333"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1931qfEdMBcoqbRhpbA/amcDzGkiRRQn2M=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: Cancel-Lock: sha1:RztCOgVMBOI5u3qPmsS7eoS2zV8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8007 On 9/13/2011 3:29 PM, Tom Anderson wrote: > Basically, lambdas can be either method-like (they return values from > themselves) or statement-like (they return values from their enclosing > methods). Lambdas are method-like in all the current dynamic languages > (AFAIK - they certainly are in Smalltalk, Python and Javascript). As I recall, Smalltalk lambdas were actually discrete blocks (Smalltalk has (almost? [1]) no control structure primitives, and I distinctly recall them allowing non-local control flow, since actual structures as we know them in Java and its ilk don't exist. Python's lambdas are single expressions (in a language that distinguishes between expressions and statements), so it can't really be classified as statement-like or method-like easily. JavaScript actually doesn't have lambdas [2], it just has first-class functions that can be defined anywhere. A more natural breakdown of lambdas, or at least clearer, is on whether or not the lambdas are designed primarily for thunking expressions (e.g., the parameter to a sort method), or if they are designed for implementing control structure. [1] My only exposure to Smalltalk was in my software engineering class (don't ask), so we never really discussed any implications of its functional paradigm. [2] Actually, distinguishing between a lambda and a function is sometimes difficult and perhaps pointless. The basic definition I'm using here is meaningful only for object-oriented languages, and it's the question of does `this' (or equivalent) refer to the same `this' as in the enclosing scope or not. JS doesn't support OO in the classical way, and how `this' gets resolved is actually handled by the way you call the method. Another metric is whether or not the syntax of defining a lambda is the same as a regular method call. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth