On Thu, 01 Sep 2011 01:21:12 +0200, Timon Gehr <timon.g...@gmx.ch> wrote:

auto foo(Range)(int n, Range r) {
     return mixin(compr!q{x * n ; x <- arr, log(x), x*x > 4});
}

This is one of the reasons I feel mixin templates should require 'mixin' only when defined, not when instantiated. Sure, it would be possible to massively
abuse that to make things completely unreadable, but I like to believe
programmers other than me are also capable of making some decisions on their
own. ;p

I still really don't like the <-. Like Kenny™ said, it already has a defined meaning that would make (some) sense in that location. <= really is no better,
and those are the two best squiggle combinations for this, I think.

Perhaps <: or := could be used. Those have no other meaning in D, and kinda
conveys what we want. Given a good IDE and keyboard, I'd love to use ∈, but
it's not really feasible.


More importantly, IMO, is that the notation does not clearly
mark what is what. is that interpreted (iota(10), log(x))
or (log(x), x*x > 4)?


It actually does. The comma is a mere separator, and imho it looks very clean.

D allows you to string expressions together using the comma operator. What does
this mean:
    [x; x <: iota(10), iota(9), true]
Is that iota(10) to be simply discarded, or is the iota(9) of value as something
other than a range for x to take elements from?


It is just like the set builder syntax you like. (it even has the curly
brackets!)

Well yes, I like that syntax. For D though, the square brackets indicate
array-like behavior, so I would like to use those.


Lastly, I feel that a library solution is suboptimal for this, even if 'mixin'
were elidible. Compare:

   compr!q{2 * x; x <: iota(10), x*x > 4};
   [2 * x; x <: iota(10); x*x > 4]

--
  Simen

Reply via email to