anonymous function/deleget usage

2009-11-12 Thread Sam Hu
How can I reach something like below code: int a=1; int b=2; int c=(int a,int b){ return a+b;} writefln(Result:%d,c); Thanks in advance.

Re: anonymous function/deleget usage

2009-11-12 Thread Joel Christensen
Sam Hu wrote: How can I reach something like below code: int a=1; int b=2; int c=(int a,int b){ return a+b;} writefln(Result:%d,c); Thanks in advance. int a=1; int b=2; int add(int a,int b) { return a+b; } int c=add(a,b); writefln(Result:%d,c); Nested functions are cool. :-)

Re: anonymous function/deleget usage

2009-11-12 Thread Don
Sam Hu wrote: How can I reach something like below code: int a=1; int b=2; int c=(int a,int b){ return a+b;} writefln(Result:%d,c); Thanks in advance. You need to call the delegate you've made. int a=1; int b=2; int c=(int a,int b){ return a+b;}(a,b); writefln(Result:%d,c);}

Re: anonymous function/deleget usage

2009-11-12 Thread Steven Schveighoffer
On Thu, 12 Nov 2009 10:21:44 -0500, Don nos...@nospam.com wrote: Sam Hu wrote: How can I reach something like below code: int a=1; int b=2; int c=(int a,int b){ return a+b;} writefln(Result:%d,c); Thanks in advance. You need to call the delegate you've made. int a=1; int b=2; int

Re: anonymous function/deleget usage

2009-11-12 Thread bearophile
Steven Schveighoffer: int c = (){return a + b;}(); You can also write: int c = {return a + b;}(); Bye, bearophile

Re: anonymous function/deleget usage

2009-11-12 Thread Ary Borenszweig
bearophile wrote: Steven Schveighoffer: int c = (){return a + b;}(); You can also write: int c = {return a + b;}(); Bye, bearophile Shorter: int c = a + b;