[DGD] Question: Implementing foreach()
Noah Gibbs
noah_gibbs at yahoo.com
Tue May 3 00:56:01 CEST 2005
--- Trance Junkie <trance_junkie2002 at hotmail.com> wrote:
> 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.
It's a good phrase. 'Course, I *would* think that... I wrote it :-)
> Firstly, is there any particular reason why DGD doesn't have built-in
> foreach() functionality?
DGD is a very minimalist driver. It doesn't implement most things that can
easily be implemented in LPC. Additionally, foreach() has some possible funky
behaviors if you're adding things to the collection, or subtracting them back
out. You can just use for() for the behavior you want, and then you *know* how
it'll act if you add or remove elements.
> Secondly, are there any plans for implementing a foreach() function in
> future releases of DGD anytime in the near future?
Nope. The big obstacle here isn't coding time - it's convincing Dworkin,
which pretty certainly won't happen.
> 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.
This would be hard. There's a parse_string() grammar that will parse LPC.
You could use that if you're good. But that's not a beginner project - if I
were you, I'd wait 'til you had more experience. Basically, since foreach()
isn't part of the language and doesn't look like a regular function call, you'd
need to do some serious code transformation before compiling stuff.
You can do this - DGD will do it for you, with enough work. But in this
case, 'enough work' is pretty substantial.
> I also understand that this will not follow the traditional (and preferable)
> foreach argument syntax of:
>
> foreach( str item in array arr )
This would require a similar amount of work.
> 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.
Yeah. This is hard to do and easy to work around, so we don't bother.
> 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.
Yes. There used to be a package to add foreach() by modifying DGD itself.
You probably don't want to do it that way, though.
> 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.
Yeah. I reiterate: this is hard to do. Not impossible, but hard.
You did good research looking for it, though! One place you skipped that
I'll mention is the mailing list archive. If you read through that and
searched for 'foreach' you'd probably find out that Dworkin isn't adding them,
and why.
__________________________________
Do you Yahoo!?
Make Yahoo! your home page
http://www.yahoo.com/r/hs
More information about the DGD
mailing list