Differentiate const flavors using CASE?

Daniel Keep daniel.keep.lists at gmail.com
Thu Mar 22 00:59:57 PDT 2007



Chris Nicholson-Sauls wrote:
> kris wrote:
>> Chris Nicholson-Sauls wrote:
>>>
>>>
>>> kris wrote:
>>>
>>>> janderson wrote:
>>>> [snip]
>>>>
>>>
>>> Or better still, if we wanted to keep 'reverse' away from the
>>> collection:
>>>
>>> foreach (item; collection) (item2; x->GetColection(b)) (item3;
>>> collection3; reverse) {
>>> }
>>>
>>> I wouldn't be above a 'foreach(i,x ; source ; order)' syntax in
>>> general, really.
>>>
>>> -- Chris Nicholson-Sauls
>>
>> Except for one thing, Chris; basing the syntax on 'keywords' limits
>> one to what the compiler chooses to support? Basing the opApply()
>> selection on a method/property name instead (with optional arguments
>> also) leaves the door wide open for any implementation you can imagine?
> 
> I was actually thinking the third "parameter" should be one of:
> function, function pointer, delegate, variable containing referance to a
> delegate; rather than some language-defined set of order keywords.
> 
> int reverse   (T,U) (int delegate(U,T) dg) {}
> int scattered (T,U) (int delegate(U,T) dg) {}
> 
> foreach (i,x ; some_array ; reverse  ) {}
> foreach (i,x ; some_array ; scattered) {}
> 
> It would seperate ordering algorithms from the collections themselves,
> and also not prevent that approach so long as the current allowance for
> delegates and usage of opApply were retained (as, presumably, they would
> be).  Just a crazy idea.
> 
> -- Chris Nicholson-Sauls

I think the third parameter should also be usable as:

> class Foo
> {
>     int opApply_scattered(...) { ... }
> }
>
> foreach (i,x ; new Foo ; scattered) {}

Reason being that if you implement "scattered" as a template, and my
class doesn't implement whatever interface you're using, I'm stuffed.

But I do rather like the thought of the third parameter being a function
of some description.  Cleanly separates the thing you're iterating over,
and *how* you're iterating over it.

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list