December 03, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 12/03/2015 05:59 PM, Steven Schveighoffer wrote:
>
> alias stableLinearXxx = linearStableXxx;
Doesn't scale. -- Andrei
| |||
December 04, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thursday, 3 December 2015 at 20:51:02 UTC, Andrei Alexandrescu wrote: > I vaguely remembered I saw something like this a while ago: > > http://dpaste.dzfl.pl/f11894a098c6 > > The trick could be more fluent, but it might have merit. Has anyone explored it? Is it a viable candidate for becoming a D idiom? > > I was looking at this in conjunction with choosing a naming convention for container functions. Some functions are "stable" so that would be part of their name, e.g. insertStable or stableInsert. With this, it's possible to write lst.stable.insert. > > > Andrei People are going to hate me, but http://dpaste.dzfl.pl/851d1d1f5e4b | |||
December 04, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On Thursday, 3 December 2015 at 20:59:59 UTC, Dicebot wrote:
> There is something wrong with the module system if one needs to resort to idioms like this.
I agree. These techniques blur the line between "idiom" and "feature abuse". They're creative and sometimes the best or only option, but they're a red flag IMO.
Mike
| |||
December 03, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On 12/03/2015 08:04 PM, Idan Arye wrote:
> People are going to hate me, but http://dpaste.dzfl.pl/851d1d1f5e4b
Win :o). -- Andrei
| |||
December 04, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On Friday, 4 December 2015 at 01:04:33 UTC, Idan Arye wrote: > > People are going to hate me, but http://dpaste.dzfl.pl/851d1d1f5e4b Doesn't seem to scale to member access: http://dpaste.dzfl.pl/37193377524c /d649/f987.d-mixin-3(7): Error: 'this' is only defined in non-static member functions, not fun Is there a way to make it work? Mike | |||
December 04, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 4 December 2015 at 01:09:07 UTC, Andrei Alexandrescu wrote:
> On 12/03/2015 08:04 PM, Idan Arye wrote:
>> People are going to hate me, but http://dpaste.dzfl.pl/851d1d1f5e4b
>
> Win :o). -- Andrei
Not win, we should feel ashamed that this is the kind of stuff you have to do.
| |||
December 03, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 12/3/15 8:01 PM, Andrei Alexandrescu wrote:
> On 12/03/2015 05:59 PM, Steven Schveighoffer wrote:
>>
>> alias stableLinearXxx = linearStableXxx;
>
> Doesn't scale. -- Andrei
To what? How many nested namespaces are you planning?
-Steve
| |||
December 04, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Mike | On Friday, 4 December 2015 at 01:37:35 UTC, Mike wrote: > On Friday, 4 December 2015 at 01:04:33 UTC, Idan Arye wrote: >> >> People are going to hate me, but http://dpaste.dzfl.pl/851d1d1f5e4b > > Doesn't seem to scale to member access: http://dpaste.dzfl.pl/37193377524c > > /d649/f987.d-mixin-3(7): Error: 'this' is only defined in non-static member functions, not fun > > Is there a way to make it work? > > Mike Yea, my bad. Initially I used a template mixin, but the syntax was ugly so I changed it to a regular template + alias. When you use a template mixin member access does work: http://dpaste.dzfl.pl/9ca85cbecea7 | |||
December 04, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Mike | On 12/04/2015 02:37 AM, Mike wrote:
> On Friday, 4 December 2015 at 01:04:33 UTC, Idan Arye wrote:
>>
>> People are going to hate me, but http://dpaste.dzfl.pl/851d1d1f5e4b
>
> Doesn't seem to scale to member access: http://dpaste.dzfl.pl/37193377524c
>
> /d649/f987.d-mixin-3(7): Error: 'this' is only defined in non-static
> member functions, not fun
>
> Is there a way to make it work?
>
> Mike
template namespace(string code,alias a=void){
mixin(code);
}
struct List{
int x;
alias stable = namespace!(q{
void fun(){
import std.stdio;
writeln(this.x);
}
},x);
}
void main(){
List lst;
lst.stable.fun();
}
:o)
| |||
December 04, 2015 Re: Pseudo namespaces | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thursday, 3 December 2015 at 20:51:02 UTC, Andrei Alexandrescu wrote:
> I vaguely remembered I saw something like this a while ago:
>
> http://dpaste.dzfl.pl/f11894a098c6
>
> The trick could be more fluent, but it might have merit. Has anyone explored it? Is it a viable candidate for becoming a D idiom?
>
> I was looking at this in conjunction with choosing a naming convention for container functions. Some functions are "stable" so that would be part of their name, e.g. insertStable or stableInsert. With this, it's possible to write lst.stable.insert.
>
>
> Andrei
Honestly I feel like scoping in D is kinda broken. IMO they need to be cleaned up a bit, with some kind of meaningful formalization of scopes, how to interact with them properly and what not. Also I think to do what you want with out fragile hacks would require some type of named scope concept added to the language.
Lots of things in the language introduce scopes, but there is no formalization on them. Modules, packages, named template instantiations, named mixin templates, structs, classes, unions, and anonymous scopes with {}. But it seems like they all have slightly different rules. There are a lot of things that have scopes but opDispatch only works on classes and structs, why? opDispatch is a scope thing, not a class or struct thing. Mixin templates have weird as fuck scope rules as well, and really should never have been added to the language. {} in a function introduces a scope but I cant name it. In a template if it has a member with the name as the template, the instantiation forwards to that member, but in structs alias this servers a similar purpose.
All these things should be related with some kind of formalized scope concept. I should be able to do "alias scopeName = { // scope stuff };" or "int scopeName.foo = 5;". Or in your problem, "void stable.fun() {...}". Also any scope should be able to have an opDispatch.
Scopes are a bit fucked up in D.
Bit of a rant, sorry..
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply