[DGD] Question: Implementing foreach()

Trance Junkie trance_junkie2002 at hotmail.com
Tue May 3 00:41:01 CEST 2005


Hello,

After a couple of years coding on a MudOS based MUD, I have decided I'd like 
to start up a unique MUD. I have decided on DGD as the preferred driver, 
mostly due to the fact that I'd rather start with an empty slate and code 
the functionality I feel is relevant to this particular MUD, which is really 
pointless to attempt with other drivers.

I'm not what you would call an 'expert programmer' by any means, but I am 
willing to 'sweat blood to learn' as it was so aptly put on one of the 
SourceForge pages. And now to the question:

Firstly, is there any particular reason why DGD doesn't have built-in 
foreach() functionality? At this point I am assuming it has for(), but I 
would have thought that foreach() would be quite useful in almost any 
multi-object server. Of course, I am just a lowly coder at this stage, so 
please bear with my apparent lack of a clue.

Secondly, are there any plans for implementing a foreach() function in 
future releases of DGD anytime in the near future? If so, is there a 
preliminary date set for the release of an updated driver with 
aforementioned function?

And thirdly, in the meantime I have attempted to hack in, at the mudlib 
level, foreach() functionality, but have come up against a little hurdle. 
How exactly do I parse the succeeding body code of a function to another 
function? In case this doesn't make any sense, I have included the following 
code which may better explain what I mean:

static void foreach(mixed item array arr)
{
  int i;
  if(sizeof(arr) < 1)
  {
    error("Empty array parsed to foreach()");
    return;
  }
  for(i=0;i>=sizeof(arr);i++)
  {
    perform_function_code(arr[i]);
  }
  return;
}

Where: 'perform_function_code()' is the function that calls and executes the 
code attached to the foreach() function. arr[i] should, as I understand lpc 
arrays to work, return the index of the array parsed to the foreach(), which 
should make this particular mudlib function, as I understand lpc code to 
work, result in the body of code attached to a foreach() function being 
executed for each item in the array parsed.

I also understand that this will not follow the traditional (and preferable) 
foreach argument syntax of:

foreach( str item in array arr )

However again, I am pretty much clueless as to how to make it so. Any help 
on this would be greatly appreciated.

I have tried looking at the other mudlibs for reference material on 
implementing this, but none of them have thus far yielded any reference to 
foreach() or similar functionality. The one example pointed to on the 
SourceForge site that does specifically mention foreach() ( On the page: 
http://phantasmal.sourceforge.net/DGD/Config/index.html ), appears to have 
been moved or removed from the web. I have even tried visiting a number of 
DGD MUDs and asking the creators of those MUDs for a spot of assistance, 
with no success.

So finally, my question is this: Is this an advisable way to implement 
foreach(), and if not, what would be a more preferable way?

Thanks for your help,

Shadow





More information about the DGD mailing list