'where' statement part II

2011-03-19 Thread bearophile
These are mostly weekend musings. I've found another possible usage for the 'where' statement. But first let me introduce the topic better. This page contains a little problem: http://csokavar.hu/blog/2010/04/20/problem-of-the-week-9-digit-problem/ The problem: Find a number

Re: Where statement

2010-07-25 Thread Michel Fortin
On 2010-07-25 09:48:21 -0400, bearophile said: Michel Fortin: Is this really an improvement over using a delegate literal? auto c = { auto a = retrieve_a(); auto b = retrieve_b(); return sqrt(a*a + b*b); }; Cute :-) I have neve

Re: Where statement

2010-07-25 Thread KennyTM~
On Jul 25, 10 21:54, Tomek Sowiński wrote: bearophile wrote: Some people have proposed the introduction in Python of the 'where' statement. It is quite used in Haskell: printFreqsBySize genome keySize = do ht0<- htNew keySize ht<- hashGenome genome keySize ht0 l<- htToList

Re: Where statement

2010-07-25 Thread Tomek Sowiński
bearophile wrote: > Some people have proposed the introduction in Python of the 'where' > statement. It is quite used in Haskell: > > printFreqsBySize genome keySize = do > ht0 <- htNew keySize > ht <- hashGenome genome keySize ht0 > l <- htToList ht

Re: Where statement

2010-07-25 Thread bearophile
Michel Fortin: > Is this really an improvement over using a delegate literal? > > auto c = { > auto a = retrieve_a(); > auto b = retrieve_b(); > return sqrt(a*a + b*b); > }; Cute :-) I have never seen this used in D code. I think you will need

Re: Where statement

2010-07-25 Thread Trass3r
Is this really an improvement over using a delegate literal? auto c = { auto a = retrieve_a(); auto b = retrieve_b(); return sqrt(a*a + b*b); }; Even more clever.

Re: Where statement

2010-07-25 Thread Kagamin
bearophile Wrote: > auto c = sqrt(a*a + b*b) where { > auto a = retrieve_a(); > auto b = retrieve_b(); > } the where statement looks as a declaration statement, but scoped block allows arbitrary statements.

Re: Where statement

2010-07-25 Thread Michel Fortin
On 2010-07-25 08:33:53 -0400, bearophile said: D lambdas can be multiline, so that's not a problem. But it can be useful to write more readable expressions when they are complex: auto c = sqrt(a*a + b*b) where { auto a = retrieve_a(); auto b = retrieve_b(); } Is this really an improv

Re: Where statement

2010-07-25 Thread bearophile
Trass3r: >You immediately give the counter-argument? ^^< I try to give both pros and cons :-) I think when expressions get even more complex 'where' can help. > Another possibility would probably be the following, but it's not as > compact and nice: > > double c; > { > double a = ret

Re: Where statement

2010-07-25 Thread Trass3r
c = sqrt(a*a + b*b) where: a = retrieve_a() b = retrieve_b() That is equivalent to: c = (retrieve_a() ** 2 + retrieve_b() ** 2) ** 0.5 You immediately give the counter-argument? ^^ Introducing a new keyword + whole new constructs gotta have substantial merit. The 2nd concept is perfe

Where statement

2010-07-25 Thread bearophile
Some people have proposed the introduction in Python of the 'where' statement. It is quite used in Haskell: printFreqsBySize genome keySize = do ht0 <- htNew keySize ht <- hashGenome genome keySize ht0 l <- htToList ht htFree ht return