On Thu, 01 Sep 2011 13:33:20 +0200, Timon Gehr <[email protected]> wrote:
On 09/01/2011 05:02 AM, kennytm wrote:
Timon Gehr<[email protected]> wrote:
On 09/01/2011 01:03 AM, Timon Gehr wrote:
On 09/01/2011 12:26 AM, Simen Kjaeraas wrote:
On Wed, 31 Aug 2011 23:54:04 +0200, Timon Gehr<[email protected]>
wrote:
[2 * x ; x<- iota(10), log(x), x*x> 4]
or, in a library:
compr!q {2 * x ; x<- iota(10), log(x), x*x> 4};
compr!q{2 * x ; x<- iota(10), log(x), x*x> 4};
The library solution has problems with scope variables.
I know, that is why I have not implemented this yet. Basically it
should
be possible to implicitly pass a whole scope to a template, or at
least,
to have local templates.
Example:
auto foo(Range)(int n, Range r) {
return compr!q{x * n; x<- arr, log(x), x*x> 4};
}
Workaround:
auto foo(Range)(int n, Range r) {
mixin Compr!q{x * n ; x<- arr, log(x), x*x> 4};
return compr;
}
but
auto foo(Range)(int n, Range r) {
return mixin(compr!q{x * n ; x<- arr, log(x), x*x> 4});
}
is clearly better.
Hey guys, the expression 'x<- arr' always means "is x less than negation
of arr?" in D. Please choose another symbol.
Yes, unless it is tokenized in a different way (which is very feasible).
Any suggestions? ∈ ?
You should try to split condition and production rules from element
feeding.
Sequence allows for any state
http://www.digitalmars.com/d/2.0/phobos/std_range.html#sequence and
has a special symbol 'n'. This idea proved to be efficient as in binaryFun.
Comp!(q{2 * a + b}, q{a * b > 4})(range, range2) would offer the same
degree of freedom as do Haskell's list comprehensions.
And even more important you restrict scope issues to only two functions,
that can use usual predicates.
P.S.:
Implementation was simpler than I'd thought.
https://gist.github.com/1186982#file_list_comprehension.d
Sorrowly there is no phobos function to create permutations and
std.functional doesn't extend to n-ary functions.
martin