static with?
Idan Arye
GenericNPC at gmail.com
Sun Dec 15 07:02:12 PST 2013
On Sunday, 15 December 2013 at 02:03:09 UTC, bearophile wrote:
> I think I'd like with() to not create a scope, just like the
> "static if". So you could write this code:
>
>
> enum Foo { A, B }
> auto x1 = Foo.A;
> auto x2 = Foo.B;
> void main() {
> import std.stdio;
> immutable data = [Foo.A, Foo.B];
> data.writeln;
> }
>
>
>
> Like this, where "with(Foo)" is usable at module scope, and it
> can be used to define an immutable and keep it visible later
> for the writeln:
>
>
> enum Foo { A, B }
> with (Foo) {
> auto x1 = A;
> auto x2 = B;
> }
> void main() {
> import std.stdio;
> with (Foo) {
> immutable data = [A, B];
> }
> data.writeln;
> }
>
>
> Assuming the current design of with() can't change, I think a
> "static with" could be used...
>
>
> enum Foo { A, B }
> static with (Foo) {
> auto x1 = A;
> auto x2 = B;
> }
> void main() {
> import std.stdio;
> static with (Foo) {
> immutable data = [A, B];
> }
> data.writeln;
> }
>
>
> Bye,
> bearophile
I don't think `static` would be a good syntax here. `static` in D
means either "belongs to the global\thread lifetime instead of
the object/function lifetime" or "performed at compile-time".
It's bad enough we have two meanings for the same keyword, but at
least `static` is a good description for both of them. `static`
does not describe well the idea of "not creating a new scope",
and I don't think it's a good idea to overload another meaning on
it and make it a whore keyword...
More information about the Digitalmars-d
mailing list