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..