digitalmars.D - isRef, isLazy, isOut
- Eldar Insafutdinov <e.insafutdinov gmail.com> Dec 19 2009
- Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> Dec 19 2009
- Walter Bright <newshound1 digitalmars.com> Dec 19 2009
- Chris Nicholson-Sauls <ibisbasenji gmail.com> Dec 20 2009
- Walter Bright <newshound1 digitalmars.com> Dec 20 2009
- Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> Dec 20 2009
- Kasumi Hanazuki <k.hanazuki gmail.com> Dec 20 2009
- Max Samukha <spambox d-coding.com> Dec 20 2009
- Eldar Insafutdinov <e.insafutdinov gmail.com> Dec 20 2009
Following the commits to the dmd repository I found these traits implemented.
The idea is good, but the API chosen does not look right. Why not have
__traits(storageClass, symbol) and a enum which defines the return value:
enum StorageClass {
None,
Ref,
Lazy,
Out
}
One could write templates isRef, isLazy etc on top of that if he/she really
needs. IMO this is a cleaner way to implement this particular feature.
Dec 19 2009
Eldar Insafutdinov wrote:Following the commits to the dmd repository I found these traits implemented. The idea is good, but the API chosen does not look right. Why not have __traits(storageClass, symbol) and a enum which defines the return value: enum StorageClass { None, Ref, Lazy, Out } One could write templates isRef, isLazy etc on top of that if he/she really needs. IMO this is a cleaner way to implement this particular feature.
I asked in vain for is(var == ref), is(var == out) etc. Andrei
Dec 19 2009
Andrei Alexandrescu wrote:I asked in vain for is(var == ref), is(var == out) etc.
That's because 'is' works with types, not symbols. It didn't fit.
Dec 19 2009
Walter Bright wrote:Andrei Alexandrescu wrote:I asked in vain for is(var == ref), is(var == out) etc.
That's because 'is' works with types, not symbols. It didn't fit.
is(typeof(var) == ref) ? -- Chris Nicholson-Sauls
Dec 20 2009
Chris Nicholson-Sauls wrote:Walter Bright wrote:Andrei Alexandrescu wrote:I asked in vain for is(var == ref), is(var == out) etc.
That's because 'is' works with types, not symbols. It didn't fit.
is(typeof(var) == ref) ?
No, because ref is not part of the type. It's a storage class.
Dec 20 2009
Walter Bright wrote:Chris Nicholson-Sauls wrote:Walter Bright wrote:Andrei Alexandrescu wrote:I asked in vain for is(var == ref), is(var == out) etc.
That's because 'is' works with types, not symbols. It didn't fit.
is(typeof(var) == ref) ?
No, because ref is not part of the type. It's a storage class.
Speaking of isLazy - any fresh ideas on dissing lazy? FWIW we can replace it with the conversion of expressions to delegates. The resulting situation is liable to a few ambiguities but is much better than lazy. Andrei
Dec 20 2009
(2009/12/21 4:43), Andrei Alexandrescu wrote:Speaking of isLazy - any fresh ideas on dissing lazy? FWIW we can replace it with the conversion of expressions to delegates. The resulting situation is liable to a few ambiguities but is much better than lazy.
Nobody seemed to mention in the last thread, but D already has the implicit expression-to-delegate conversion in the type-safe variadic parameters. (only available in the last part of parameters though...) Can we merge lazy with it? ---- void f(void delegate()[1] gs...) { gs[0](); gs[0](); } void g() { writeln(42); } void main() { f(g()); }
Dec 20 2009
On 19.12.2009 23:00, Walter Bright wrote:Andrei Alexandrescu wrote:I asked in vain for is(var == ref), is(var == out) etc.
That's because 'is' works with types, not symbols. It didn't fit.
Will there be a way to get storage classes from function symbols or types? Currently, we have to use a Signature template that, along with parameter and return types, extracts storage classes by parsing the value of parameter type tuple's stringof. Ugly and unreliable. We need a way to do it without resorting to hacks. Something in this vein: enum StorageClasses { ... } class A { ref int foo(const ref int a, lazy int b) const; void bar(out a); } assert(__traits(storageClasses, A.foo) == StorageClasses.Const | StorageClasses.Ref); assert(__traits(parameterStorageClasses, A.foo) == [StorageClasses.Const | StorageClasses.Ref, StorageClasses.Lazy]); See also http://d.puremagic.com/issues/show_bug.cgi?id=1818
Dec 20 2009
Max Samukha Wrote:On 19.12.2009 23:00, Walter Bright wrote:Andrei Alexandrescu wrote:I asked in vain for is(var == ref), is(var == out) etc.
That's because 'is' works with types, not symbols. It didn't fit.
Will there be a way to get storage classes from function symbols or types? Currently, we have to use a Signature template that, along with parameter and return types, extracts storage classes by parsing the value of parameter type tuple's stringof. Ugly and unreliable. We need a way to do it without resorting to hacks. Something in this vein: enum StorageClasses { ... } class A { ref int foo(const ref int a, lazy int b) const; void bar(out a); } assert(__traits(storageClasses, A.foo) == StorageClasses.Const | StorageClasses.Ref); assert(__traits(parameterStorageClasses, A.foo) == [StorageClasses.Const | StorageClasses.Ref, StorageClasses.Lazy]); See also http://d.puremagic.com/issues/show_bug.cgi?id=1818
Please, please...
Dec 20 2009









Kasumi Hanazuki <k.hanazuki gmail.com> 