[phobos] phobos commit, revision 1737
Andrei Alexandrescu
andrei at erdani.com
Thu Jul 8 10:40:56 PDT 2010
On 07/08/2010 11:01 AM, Shin Fujishiro wrote:
> Michel Fortin<michel.fortin at michelf.com> wrote:
>> Le 2010-07-08 à 8:13, Andrei Alexandrescu a écrit :
>>
>>> This is solid work! There's an opportunity here - it overlaps a LOT
>>> with std.variant.Algebraic.
>>
>>
>> Indeed. It's great. But why is the protection level set to 'package'?
>> Isn't it meant to be used outside of Phobos?
>
> I needed it to implement native codeset support in stdio. I just went
> conservative for adding a public stuff that people might not use...
Cool, looking forward to seeing the result. For all I know Ruby was very
successful in Japan because it had support for the Japanese character
sets from day one.
>> One thing I've missed about Algebraic is the ability to switch on the
>> type, somewhat like this:
>>
>> Algebraic!(A, B, C) x;
>> switch (x.type) {
>> case x.typecode!A:
>> case x.typecode!B:
>> case x.typecode!C:
>> ...
>> }
>>
>> Seems like this would be easy by switching on Any's _duckID, but this
>> facility isn't exposed (it's all private).
>
> It's nice. I'll add it!
>
> switch (x.Algebraic.type) {
> case x.Algebraic.typeCode!A:
> case x.Algebraic.typeCode!B:
> ...
> default:
> }
I don't think that's very useful because you need to follow each case
with a peek() or something. I was thinking it would be great to define a
dispatcher a la Sean's receive():
x.Algebraic.dispatch(
(A obj) { writeln("saw an A"); },
(B obj) { writeln("saw a B"); },
...
);
Such a dispatch function could come in two flavors: strict and non-strict.
Andrei
More information about the phobos
mailing list