Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: BGB Newsgroups: comp.lang.java.programmer Subject: Re: new Java lambda syntax Date: Thu, 08 Sep 2011 22:23:56 -0700 Organization: albasani.net Lines: 105 Message-ID: References: <4e694f5f$0$311$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.albasani.net /Ov9Tk2QFbh3qdp6pCh5ooCJPs/8xeUP55yQDwieFta2tKYHMDrdoAAuqfPggZCCUmaGWDxh8SyQCndIRf0tGw== NNTP-Posting-Date: Fri, 9 Sep 2011 05:23:59 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="BGrnxLM1GuNkK6G2afH+H3aJmuN36nnrt1HRk0Mg8+CCFqPoB+Zlhc5sv6+/KvdCKixXJB7zNHLSxFr5xExvaFhCnUmcpzbRM+GxNeU50y29uVJC7So8cFIE8OUI67rO"; mail-complaints-to="abuse@albasani.net" 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:W2QmHqPMfQwcjydqZxFeSQg3qZA= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7746 On 9/8/2011 5:56 PM, Peter Duniho wrote: > On 9/8/11 4:29 PM, BGB wrote: >> [...] >>> As a curiosum then C# also allows: >>> >>> delegate(int x) { return x+1; } >>> >> >> this was their older syntax, before they added "=>", why? who knows... > > The "=>" syntax was introduced as part of a broader application, the > more general lambda expression feature. In certain contexts, a C# lambda > expression becomes an anonymous method, but in other contexts, it > becomes a specific kind of expression type. > > The "delegate" syntax predates the generalized lambda expression and is > usable _only_ for anonymous methods. In that context, it makes a lot of > sense, because anonymous methods can be referenced only via a delegate > instance, so reusing the keyword to express that gives some continuity. > fair enough... >> delegate would work, except it is a question if the Java people would >> have wanted to add this keyword either... > > I haven't seen anything about the syntax for a new function pointer type > in Java to use with a lambda. Maybe that's what the message from Goetz > means when he writes "…have not yet come to a decision on method > reference syntax". But it's possible that _some_ new keyword will yet > need to be added. > I wouldn't know, I don't subscribe to that list, so I have no idea what is going on there. > Whether that's "delegate" or something else, who knows? (Well, okay…I'll > bet someone does. I just haven't been keeping up on the issue, so _I_ > don't know). > "int (*foo)(int x);" ok, maybe not... in my own language, I use the 'typedef' keyword in a manner similar to C#'s use of the 'delegate' keyword (and my language uses 'delegate' for something almost entirely different). but, possible could be something like: typedef int FooMethodType(int x); ... FooMethodType assignableMethod; ... assignableMethod = (int x)=>x+1; or: assignableMethod = FooMethodType=>x+1; in my own syntax, it would be more like: typedef function FooMethodType(x); ... var assignableMethod:FooMethodType; ... assignableMethod = fun(x) x+1; although, possibly nice: assignableMethod = FooMethodType=>x+1; where, in my language, typedef is technically a modifier (it is not a syntactic form, and also has no effect on parsing in any way, unlike in C or C++). now, what do I use 'delegate' for? for inter-object delegation (technically, it is a scoping feature). basically, it makes object variables "transparent", so that the fields/methods/... located within the referenced objects may be accessed as if they were part of the current scope (basically, sort of like "static import" but with object instances and variables, and it may apply recursively). attempting to access a variable or call a method may forward the request to the object in question (with some edge-case semantics WRT instance methods, but I will not really go into this). note that it still respects 'private' and similar. technically, in this language, packages are themselves implemented as objects (and imports are internally implemented using variables linking to said package-objects). implicitly, "this" may be considered as itself analogous to a delegate variable, but my language allows implementing more variables with similar behavior (and also allows building a "toplevel" out of a patchwork of linked object instances). or such...