Andrei Alexandrescu wrote:
Michel Fortin wrote:
That seems reasonable, although if we support it it shouldn't be limited to regular expressions for coherency reasons. For instance:

    foreach(e; "co" in "conoco")
        writeln(e);

should work too. If we can't make that work in the most simple case, then I'd say it shouldn't with the more complicated ones either.

Well I'm a bit unhappy about that one. At least in current D and to yours truly, "in" means "fast membership lookup". The use above is linear lookup. I'm not saying that's bad, but I prefer the non-diluted semantics. For linear search, there's always find().

At least, "in" refers to a look-up, whereas "~" refers to concatenation, which has nothing in common with the regex matching.

Furthermore, we can't make any complexity guarantees for operators; this always depends on the data structure you use the operator on. And, if I'm not mistaken, "in" is only used by the associated array at the moment. It's a "fast look-up" because of the associated array, but it doesn't have to be.

(Similarly, to me, ~ and ~= feel slow, O(n), but that shouldn't keep us from using it with other data structures that can do a similar concat/append operation with lower complexity.)

L.

Reply via email to