September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory McGuire | On Wednesday, 4 September 2013 at 09:23:44 UTC, Rory McGuire wrote: > thanks, yes, I just found that in TDPL. knew it was templates but forgot > about template mixins. > > Do you know how to get a default parameter like __MODULE__ or __LINE__ to > be used from the calling site? > I've tried but I think my DMD is broken because it doesn't even work when I > subclass Exception(). Special tokens like __LINE__ in default parameters are evaluated at the call site: http://dpaste.dzfl.pl/f7b9dfcf It does not help though, because you don't need __MODULE__ of the call site, you need list of modules it has imported in exact call scope. |
September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot Attachments:
| Thanks, the exact example is exceptions. Was working really late the day that it wasn't working :D my bad. The following is what I was after, which I really thought I had tried.
class BaseException : Exception {
this(string s="", string file = __FILE__, int line = __LINE__) {
super(s, file, line);
}
}
On Wed, Sep 4, 2013 at 11:33 AM, Dicebot <public@dicebot.lv> wrote:
> On Wednesday, 4 September 2013 at 09:23:44 UTC, Rory McGuire wrote:
>
>> thanks, yes, I just found that in TDPL. knew it was templates but forgot about template mixins.
>>
>> Do you know how to get a default parameter like __MODULE__ or __LINE__ to
>> be used from the calling site?
>> I've tried but I think my DMD is broken because it doesn't even work when
>> I
>> subclass Exception().
>>
>
> Special tokens like __LINE__ in default parameters are evaluated at the call site: http://dpaste.dzfl.pl/f7b9dfcf
>
> It does not help though, because you don't need __MODULE__ of the call site, you need list of modules it has imported in exact call scope.
>
|
September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Attachments:
| I have a basic solution but it can't handle basic types LOL! you have to typedef them so that moduleName!T works. and then the functions have to be declared in the same module as the type. Or alternatively you have to specify the module to use e.g. Implements!(T,MyInterface, "mymodule"). http://dpaste.dzfl.pl/cff0ca5a I had to hard code the module name because dmd segfaults if you use __MODULE__ in the contraint. Both references to asdf should be changed to the module you are using. On Wed, Sep 4, 2013 at 11:48 AM, Rory McGuire <rjmcguire@gmail.com> wrote: > Thanks, the exact example is exceptions. Was working really late the day that it wasn't working :D my bad. The following is what I was after, which I really thought I had tried. > > class BaseException : Exception { > this(string s="", string file = __FILE__, int line = __LINE__) { > super(s, file, line); > } > } > > > On Wed, Sep 4, 2013 at 11:33 AM, Dicebot <public@dicebot.lv> wrote: > >> On Wednesday, 4 September 2013 at 09:23:44 UTC, Rory McGuire wrote: >> >>> thanks, yes, I just found that in TDPL. knew it was templates but forgot about template mixins. >>> >>> Do you know how to get a default parameter like __MODULE__ or __LINE__ to >>> be used from the calling site? >>> I've tried but I think my DMD is broken because it doesn't even work >>> when I >>> subclass Exception(). >>> >> >> Special tokens like __LINE__ in default parameters are evaluated at the call site: http://dpaste.dzfl.pl/f7b9dfcf >> >> It does not help though, because you don't need __MODULE__ of the call site, you need list of modules it has imported in exact call scope. >> > > |
September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory McGuire | On Wednesday, 4 September 2013 at 10:33:26 UTC, Rory McGuire wrote:
> I have a basic solution but it can't handle basic types LOL! you have to
> typedef them so that moduleName!T works.
Of course it can't, built-in types don't have any owning module, those are not symbols. Why would you want to care about basic types anyway?
|
September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot Attachments:
| yip, :) can't think of a reason except it was interesting. wish dmd didn't segfault when I used __MODULE__. on the plus side the requirement for a non basic type is the same requirement that #golang has on its interfaces. On Wed, Sep 4, 2013 at 12:48 PM, Dicebot <public@dicebot.lv> wrote: > On Wednesday, 4 September 2013 at 10:33:26 UTC, Rory McGuire wrote: > >> I have a basic solution but it can't handle basic types LOL! you have to typedef them so that moduleName!T works. >> > > Of course it can't, built-in types don't have any owning module, those are not symbols. Why would you want to care about basic types anyway? > |
September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory McGuire | On 2013-09-04 13:01, Rory McGuire wrote: > yip, :) can't think of a reason except it was interesting. wish dmd > didn't segfault when I used __MODULE__. > > on the plus side the requirement for a non basic type is the same > requirement that #golang has on its interfaces. Do you have a module declaration? -- /Jacob Carlborg |
September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg Attachments:
| Thanks! a module declaration gets around that one. http://dpaste.dzfl.pl/cff0ca5a line 21 On Wed, Sep 4, 2013 at 1:18 PM, Jacob Carlborg <doob@me.com> wrote: > On 2013-09-04 13:01, Rory McGuire wrote: > >> yip, :) can't think of a reason except it was interesting. wish dmd didn't segfault when I used __MODULE__. >> >> on the plus side the requirement for a non basic type is the same requirement that #golang has on its interfaces. >> > > Do you have a module declaration? > > -- > /Jacob Carlborg > |
September 04, 2013 Re: Little demo of allowing basic types to implement interfaces. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory McGuire | On 2013-09-04 13:57, Rory McGuire wrote: > Thanks! a module declaration gets around that one. > http://dpaste.dzfl.pl/cff0ca5a line 21 I think this should already be fixed in git HEAD. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation