Yes indeed, null initial value is reasonable. My suggestion does
not affect that rationale, but is only based on my observation
that if someone want to `refer` to an AA, he is more likely to
fill it very soon, and he really mean to refer to it. These are
similar concerns:
- create a null AA,
It's an optimization of memory allocation: you can always have a
usable AA without allocating anything for it, so when you fill it
with data, you may want to assign it back to where it should
stay, similar to a slice.
Indeed it's confusing.
So AA is a value type that behaves like a pointer/reference.
We can add a rule to the initialization to make AA behave more
like reference types:
If someone `refer` to an unitialized AA, that is, by doing:
```d
string[string] aa;
string[string] bb = aa; // bb `refers`
On Thu, Aug 07, 2014 at 02:00:27AM +, Puming via Digitalmars-d-learn wrote:
> On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote:
[...]
> >Indeed, it was just what the OP suspected as the culprit.
>
> You are right, I didn't know about the AA initialization problem then.
>
> When
On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote:
On Wednesday, 6 August 2014 at 15:18:15 UTC, Dragos Carp wrote:
On Wednesday, 6 August 2014 at 14:36:23 UTC, Marc Schütz wrote:
This would defeat the purpose, see the original post.
sorry, I red just the last post.
__gshared ha
This describes the semantics of regular arrays. Are you sure it
also applies to AAs? I thought they will keep referring to the
same data once they are initialized. But I might be mistaken...
This can be easily tested. And... you are right!
In the current implementation (I couldn't find any
On Wednesday, 6 August 2014 at 15:18:15 UTC, Dragos Carp wrote:
On Wednesday, 6 August 2014 at 14:36:23 UTC, Marc Schütz wrote:
This would defeat the purpose, see the original post.
sorry, I red just the last post.
__gshared has no influence on this.
Indeed, it was just what the OP suspect
On Wednesday, 6 August 2014 at 14:36:23 UTC, Marc Schütz wrote:
This would defeat the purpose, see the original post.
sorry, I red just the last post.
__gshared has no influence on this.
auto cmds = CONFIG.commands;
cmds["list"] = new Command(...);
cmds is a thread local variable referenc
On Wednesday, 6 August 2014 at 14:22:32 UTC, Dragos Carp wrote:
1. The only way that I can initialize it is to assign a value.
But I want to initialize an empty AA, is that possible?
--snip--
This means if you want an empty AA you can write
aa1 = null;
or more explicit
aa1 = typeof(aa1).i
1. The only way that I can initialize it is to assign a value.
But I want to initialize an empty AA, is that possible?
Like arrays, associative arrays have value semantics. This means
that they can be always referenced.
It is easier to see this with an array:
int[] a1 = null;
writeln(a1.pt
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote:
1. The only way that I can initialize it is to assign a value.
But I want to initialize an empty AA, is that possible?
workaround:
string[string] aa;
assert(aa is null);
aa[""] = "";
aa.remove("");
assert(aa !is null);
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote:
On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote:
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
1. Are AAs reference type? if so, why does the compiler copy
it?
This is probably your problem. They are reference
On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote:
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
1. Are AAs reference type? if so, why does the compiler copy
it?
This is probably your problem. They are reference types, but
initially that reference is `null`. When you wri
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
1. Are AAs reference type? if so, why does the compiler copy it?
This is probably your problem. They are reference types, but
initially that reference is `null`. When you write:
auto cmds = CONFIG.commands;
`cmds` contains a copy
V Thu, 31 Jul 2014 02:03:35 +
Puming via Digitalmars-d-learn
napsáno:
> Hi,
>
> I'm writing this global Config class, with an AA member:
>
> ```d
> module my.config;
>
> class Config
> {
> Command[string] commands;
> }
>
> __gshared Config CONFIG;
> ```
>
> and initialize it in anot
Hi,
I'm writing this global Config class, with an AA member:
```d
module my.config;
class Config
{
Command[string] commands;
}
__gshared Config CONFIG;
```
and initialize it in another module:
```d
module my.app;
import my.config;
void main()
{
CONFIG = new Config();
CONFIG.command
16 matches
Mail list logo