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: Compilation constants

2009-11-12 Thread Chris Nicholson-Sauls
Phil Deets wrote: On Wed, 11 Nov 2009 13:45:17 -0500, grauzone wrote: You can delete your posts to emulate editing... I didn't know it was possible to delete posts from a newsgroup. How do you do that? I don't know about any other readers, but using Thunderbird just right-click the messa

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 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 c=(int a,int b){

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;

Re: Compilation constants

2009-11-12 Thread Phil Deets
On Thu, 12 Nov 2009 07:17:57 -0500, Chris Nicholson-Sauls wrote: Phil Deets wrote: On Wed, 11 Nov 2009 13:45:17 -0500, grauzone wrote: You can delete your posts to emulate editing... I didn't know it was possible to delete posts from a newsgroup. How do you do that? I don't know abo

Re: anonymous function/delegate usage

2009-11-12 Thread Sam Hu
Don Wrote: > You need to call the delegate you've made. I missed this key point. So to summary: int a=1; int b=2; 1.nested function; 2.int c=(int a,int b){return a+b;}(a,b); 3.int c=(int,int){return a+b;}(a,b); 4.int c=(){return a+b;}(); 5.int c={return a+b;}(); How come the last one is legal?

Fixed point arithmetic

2009-11-12 Thread g
is there any library for D that implements fixed point arithmetic. g

Re: anonymous function/delegate usage

2009-11-12 Thread BCS
Hello Sam, Don Wrote: You need to call the delegate you've made. I missed this key point. So to summary: int a=1; int b=2; 1.nested function; 2.int c=(int a,int b){return a+b;}(a,b); 3.int c=(int,int){return a+b;}(a,b); 4.int c=(){return a+b;}(); 5.int c={return a+b;}(); How come the last o

Re: anonymous function/delegate usage

2009-11-12 Thread Sam Hu
BCS Wrote: > If the function has no args the first () can be dropped. > If the return type can be inferred, that can be dropped. > Nested functions can access vars in the outer function. > Got it.Thanks a lot!