Few things

Vladimir Panteleev thecybershadow at gmail.com
Fri Aug 3 03:41:58 PDT 2007


On Fri, 03 Aug 2007 10:39:41 +0300, bearophile <bearophileHUGS at mailas.com> wrote:

> With that the creation of an AA becomes an expression, so you can use it inside just a line, like
>
> return AA!(int, string);
>
> Instead of:
>
> string[int] aa;
> return aa;
>
> That's a silly example, but expressions are useful in other situations too.
> Note that for dynamic arrays you can do that already:
>
> return new string[];

In both cases you can just "return null;", which will work in most cases.

> Note (I am not suggesting this for D, I am just showing): Python cares even more to avoid common bugs, you can't even do this:
> while (a = b + c) { ... }
> Assignments aren't expressions, this is forbidden just to avoid the bugs caused to confusing == and =. (Pascal avoids part of those bugs because it uses := as assignment, that's more easy to distinguish from = to test for equality).

You can't do this in D either ('=' does not give a boolean result). Check your facts before posting ;)

> Sean Kelly>All sound useful, though it may be confusing to have AA.sort behave differently than array sort.<
>
> I agree. But they are different data structures, so maybe such "confusion" is worth it.

Have you considered using:
	foreach(key;aa.keys.sort)
		writefln(key, " => ", aa[key]);


> Kirk McDonald>Simply assign the AA to null. That is the empty AA.<
>
> It seems you all have missed my point here (probably for my fault), I was talking about creating (and defining) an AA, not cleaning an existing one. See my answer to Sean Kelly.

"null" works as a "literal" expression for arrays and AAs. That's why "cleaning" works - it simply sets the reference to null, and the GC will clean up the old contents sooner or later.


P.S. Your method of replying is very confusing, it's almost impossible to find the actual context of your messages. What newsreader software do you use?

-- 
Best regards,
  Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list