digitalmars.D.learn - Cleared AA == and is have different results. Why?
- Brother Bill (30/30) Sep 10 Page 119 of Programming in D
- IchorDev (9/10) Sep 10 You have already asked this question [here
- Brother Bill (2/12) Sep 10 Thank you so much. Got it.
- Nick Treleaven (10/14) Sep 10 Feature. An AA has reference semantics. Removing all elements
Page 119 of Programming in D
It seems odd that == null and is null have different values?
Is this a bug or feature?
If a feature, what is the meanings of == null vs. is null?
source/app.d
```
import std.stdio;
void main()
{
// value[key]
int[string] dayNumbers =
// key : value
[
"Monday": 0, "Tuesday": 1, "Wednesday": 2,
"Thursday": 3, "Friday": 4,
"Saturday": 5, "Sunday": 6
];
dayNumbers.remove("Tuesday");
// writeln(dayNumbers["Tuesday"]); // ← run-time ERROR
dayNumbers.clear;
writeln("dayNumbers == null? ", dayNumbers == null);
// Better, use 'is'
writeln("dayNumbers is null? ", dayNumbers is null);
}
```
Console output:
```
dayNumbers == null? true
dayNumbers is null? false
```
Sep 10
On Wednesday, 10 September 2025 at 14:01:29 UTC, Brother Bill wrote:what is the meanings of == null vs. is null?You have already asked this question [here before](https://forum.dlang.org/thread/nvaiwzvcrahnwziorazc forum.dlang.org). The spec outlines the meaning of equality and identity expressions here: - https://dlang.org/spec/expression.html#equality_expressions - https://dlang.org/spec/expression.html#identity_expressions You should try to reference the spec when you don't understand something. It's essentially the best resource for learning about D's finer points.
Sep 10
On Wednesday, 10 September 2025 at 14:25:05 UTC, IchorDev wrote:On Wednesday, 10 September 2025 at 14:01:29 UTC, Brother Bill wrote:Thank you so much. Got it.what is the meanings of == null vs. is null?You have already asked this question [here before](https://forum.dlang.org/thread/nvaiwzvcrahnwziorazc forum.dlang.org). The spec outlines the meaning of equality and identity expressions here: - https://dlang.org/spec/expression.html#equality_expressions - https://dlang.org/spec/expression.html#identity_expressions You should try to reference the spec when you don't understand something. It's essentially the best resource for learning about D's finer points.
Sep 10
On Wednesday, 10 September 2025 at 14:01:29 UTC, Brother Bill wrote:Page 119 of Programming in D It seems odd that == null and is null have different values? Is this a bug or feature? If a feature, what is the meanings of == null vs. is null?Feature. An AA has reference semantics. Removing all elements does not set it to `null` (the `.init` value), because it is already allocated, which may be useful for future operations. Comparing for equality against null is true because both AA references have no elements (null is a valid AA reference). Comparing for identity is false because `null` has no AA allocation whereas `dayNumbers` does - it isn't null. https://dlang.org/spec/hash-map.html#construction_and_ref_semantic
Sep 10









Brother Bill <brotherbill mail.com> 