Re: why can't structs implement interfaces?
Saaa a écrit : struct S : Pos {} Why is this not possible? It's not and structures have no vtable... fortunately. But, could it be a good idea to use the "inheritance operator" to do some kind of static inheritance like we do with mixins or to force implementation at compile-time ? 1. inheriting from an interfaces would force function implementation at compile time: interface IFoo { void foo(); } // Would not compile // "Struct S static interface function IFoo.foo isn't implemented" struct S : IFoo {} // Would compile struct S : IFoo { void foo() {} } 2. inheriting from a structure would do some kind a mixin. struct S1 { void foo(); static void bar(); } struct S2 : S1 {} S1.bar(); S1 a; a.foo(); a.bar(); 3. class and structs could share interfaces for compile time function name resolution. I think this already work using untyped template arguments. interface IFoo { void foo(); } class C : IFoo // dynamic inheritance { void foo() { } } struct S : IFoo // static inheritance { void foo() { } } class Bar(IFoo FOO) { void bar(FOO thing) { thing.foo(); } } 4. casting could be forbidden OR : struct A { int a; } struct B : A {} // B implements "int a" as in 2 A a; B b = a; // would do something like b.a = a.a B b; A a = b; // would do something like a.a = b.a -- AF
Re: why can't structs implement interfaces?
Don: > Please don't do that just yet. It's something that can wait until the D2 > stuff is finished. It can be added at any time. Some of the other things > are urgent. OK :-) You are right, as usual. Bye, bearophile
Re: why can't structs implement interfaces?
bearophile wrote: Don: That's been requested many times. I posted a patch to Walter to do exactly that. It was beautiful. It detected recursive template expansions, and gave really nice error messages. Silently rejected. Sigh. If your patch is well done, works with LDC too, I see no reason to refuse this feature even for D1, it doesn't change the language and just makes debugging simpler. So let's not surrender yet. How much time ago Walter has refused this patch? Lately Walter is more receptive for your patches. I can create a new thread about this in the main D NG. If 8+ persons say they want this patch, and it works correctly, then Walter can change his mind. Please don't do that just yet. It's something that can wait until the D2 stuff is finished. It can be added at any time. Some of the other things are urgent.
Re: why can't structs implement interfaces?
Lars T. Kyllingstad: > What's the bugzilla number? Should be upvoted. I think he refers to this one (searching something in Bugzilla seems a good way to spend a morning): http://d.puremagic.com/issues/show_bug.cgi?id=2816 In the comment 9, instead of: bug.d(2): Error: static assert (0) is false bug.d(9):instantiatied from here: bar!() bug.d(14):100 recursive instantiations from here: foo!(196) bug.d(19):253 recursive instantiations from here: baz!(300) Someone may prefer them listed in inverted order: bug.d(19): ... bug.d(14): ... bug.d(9): ... bug.d(2): ... Bye, bearophile
Re: why can't structs implement interfaces?
Don: > That's been requested many times. I posted a patch to Walter to do > exactly that. It was beautiful. It detected recursive template > expansions, and gave really nice error messages. Silently rejected. > Sigh. If your patch is well done, works with LDC too, I see no reason to refuse this feature even for D1, it doesn't change the language and just makes debugging simpler. So let's not surrender yet. How much time ago Walter has refused this patch? Lately Walter is more receptive for your patches. I can create a new thread about this in the main D NG. If 8+ persons say they want this patch, and it works correctly, then Walter can change his mind. Bye, bearophile
Re: reading files from a directory
miriac <1234...@gmail.com> wrote: > Jesse Phillips Wrote: > >> miriac Wrote: >> >> > I'm trying to get my program to read all the files in a directory. >> > dmd gives an errer that theis imports dont exist: >> > tango.io.FileSystem, >> > tango.io.FileRoots, >> > Can someone please help me and tell me what i use to do so? >> > thanxs >> > M >> >> As jcc7 mentioned it sounds like you're using a Tango example without installing Tango first. For more details about starting with D: >> >> http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/StartingWithD > > I really do want to stick to tongo, i instaled it with the instructions in > the tongo book but i can try downlding it again and see if it works > thanks > My reply before checking the docs: if its not working after installation then the import paths are incorrect. you could start by checking that. and also note that tango trunk and the latest tango release are somewhat different. also it looks like you should be using trunk because the next release is due out shortly. My reply after checking the api docs: I don't see tango.io.FileRoots anywhere, check the version of tango you are trying to use.
Re: why can't structs implement interfaces?
"Saaa" wrote: > struct S : Pos {} > Why is this not possible? > > > Why do you want to use a struct for that, rather than a class?
Re: why can't structs implement interfaces?
Don wrote: bearophile wrote: Bill Baxter: The good thing is that since most of the machinery is there, the actual compiler changes required would mostly be just rewrites of new syntax in terms of existing functionality. I agree, this looks like something that can be added to D even after D2 comes out of alpha. But Andrei warns us that here it's easy to overdo the design. So I think that keeping usability low (= keeping things handmade and low-tech) can be better than a Byzantine and limited design. In particular there's not a good way for the compiler to give good error messages about why a concept is not satisfied by a particular type. Time ago I have asked for a "small" compiler feature: when a function/class template creates a compile-time error (because some of the code inside it is not compatible with the specific type given to the template) I'd like the D compiler to act as GCC, telling me not just where there is the error inside the template, but also and *before* that error message to show me the line of where the template is instantiated. This is another small feature that can be added after D2 "finalization". That's been requested many times. I posted a patch to Walter to do exactly that. It was beautiful. It detected recursive template expansions, and gave really nice error messages. Silently rejected. Sigh. What's the bugzilla number? Should be upvoted. -Lars
Re: why can't structs implement interfaces?
bearophile wrote: Bill Baxter: The good thing is that since most of the machinery is there, the actual compiler changes required would mostly be just rewrites of new syntax in terms of existing functionality. I agree, this looks like something that can be added to D even after D2 comes out of alpha. But Andrei warns us that here it's easy to overdo the design. So I think that keeping usability low (= keeping things handmade and low-tech) can be better than a Byzantine and limited design. In particular there's not a good way for the compiler to give good error messages about why a concept is not satisfied by a particular type. Time ago I have asked for a "small" compiler feature: when a function/class template creates a compile-time error (because some of the code inside it is not compatible with the specific type given to the template) I'd like the D compiler to act as GCC, telling me not just where there is the error inside the template, but also and *before* that error message to show me the line of where the template is instantiated. This is another small feature that can be added after D2 "finalization". That's been requested many times. I posted a patch to Walter to do exactly that. It was beautiful. It detected recursive template expansions, and gave really nice error messages. Silently rejected. Sigh.