[DGD] foreach

Derek Hartley flatline4010 at yahoo.co.uk
Thu Sep 8 17:29:01 CEST 2005


Well, at the risk of pointing out the obvious wouldn't
the foreach() you're requesting be written exactly the
same way you're doing it here? So you could simply
implement it yourself.

--- solicit <solicit at hot.ee> wrote:

> I am currently trying to port a mudlib from MudOS to
> DGD, and I've hit a major show-stopper - foreach.
> Just so you know, I've read the mailing list
> archives threads about it.
> 
> I can agree that sometimes it is better and clearer
> to use for() instead of foreach() when iterating
> over an array, but no so for a mapping. Consider
> this example:
> 
> With foreach:
> mapping m;
> m["a"] = "foo";
> m["b"] = "bar";
> foreach(key, value in m) {
>     printf("key: %s, value: %s\n", key, value);
> }
> 
> Without foreach:
> mapping m;
> string key, value; /* (if the mapping is
> declared/filled in somewhere else, then it can be
> hard to guess the type [although you could use
> mixed]) */
> string *keys;
> int i;
> 
> m["a"] = "foo";
> m["b"] = "bar";
> keys = keys(m);
> for(i = 0; i < sizeof(keys); i++) {
>     key = keys[i];
>     value = m[key];
>     printf("key: %s, value: %s\n", key, value);
> }
> 
> That's about twice as long (thrice if you don't
> count the filling-in-the-mapping part). Now consider
> me having to go through the 2300+ instances of
> foreach() in my mudlib (easily over half of them
> critical), and changing them all. Not something I'd
> like to do.
> 
> Now, if someone happens to have the old patch for
> DGD that adds foreach, then you can just ignore all
> this, but I thought I'd present my argument first.
> :)
> 
> -----------------------------------------
> ITV - Sinu lemmiksaated internetis!
> http://www.itv.ee
> 
> __________________________________________
> http://mail.dworkin.nl/mailman/listinfo/dgd
> 



	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com



More information about the DGD mailing list