Huffman coding comparison

Simen kjaeraas simen.kjaras at
Sun May 30 08:27:26 PDT 2010

Philippe Sigaud <philippe.sigaud at> wrote:

> That's fun to see, the syntax is cool. I never thought of using operator
> overloading for this.

I just had a look at Wikipedia's article on it, found that the syntax was
somewhat approachable in D's operator overloading, and thought
'hey, that's neat'. Just wish I could use curly brackets around it, but
parentheses work:

{ 2·x | x ∈ N, x² > 3 }
( list!"2*a" | iota(1,int.max) * where!"x^^2 > 3" )

> I did a range comprehension also, a few months ago. It's called comp in
> Like yours, it takes any range and is lazy, the main difference it that  
> it's
> multirange: you can give it any number of range as input, it will create  
> the
> combinations of elements (aka product of ranges), filter it with the
> predicate and map the generative function on it.
> auto pyth(int n)
> {
>     return comp ! ("tuple(a,b,c)", "a*a+b*b==c*c && a<b")
> (iota(1,n),iota(1,n), iota(1,n));
> }

This reminded me that Phobos lacks a combinatorial range, taking two or
more (forward) ranges and giving all combinations thereof:

(0,2), (0,3), (1,2), (1,3)

Work has commenced on implementing just that.


More information about the Digitalmars-d mailing list