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
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
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
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
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
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.
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.
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
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
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
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
11 matches
Mail list logo