February 17, 2006
pragma wrote:

>> # foreach("\w*" ~~ "hello world"){
>> #   writefln("match: #%d is %s",$.key,$.value);
>> # }

This would mean that you had to type $.value.match(0), which is even more verbose than the _match.match(0) $ was intended to help make shorter.

My suggestion is that $ by itself refers to the value.

If it is necessary to have something to refer to the key, it could be called $key, but maybe the only way to get the key should be to use the full form: foreach(int i, int x; arr)...
(and if there was a $key, maybe $value should be an alias to $...)

> *Branching (?: operator)
> 
>> # Foobar foo = getFoobar() ? $ : new Foobar();

I kind of like this one, but it is not very obvious to whoever reads the code that a new scope has been introduced... One will really have to be aware of the often changing binding of $.

I otherwise agree with you on what $ should bind to.

/Oskar
1 2
Next ›   Last »