|
Virus Wanderer
Joined: 29 Jun 2002 Posts: 69 Location: USA
|
Posted: Thu Feb 13, 2003 5:08 am
iter() |
Ok, we all know that muxes and mushs have commands similar to #LOOP called @dolist. Now what I want to know is there a ZMUD function similar to iter()? If there it it would be awesome.
Richard Powell
Mux Alias: Virus
2796 Wizard Staff
64.89.10.1 port 2796
Rich@gigdev.com |
|
|
|
Emit Magician
Joined: 24 Feb 2001 Posts: 342 Location: USA
|
Posted: Thu Feb 13, 2003 5:41 am |
maybe if you could explain a little more, i just play merc derivatives mainly.
--------
moon.icebound.net:9000 |
|
|
|
Virus Wanderer
Joined: 29 Jun 2002 Posts: 69 Location: USA
|
Posted: Thu Feb 13, 2003 6:56 am |
Function: iter(list, eval[, delim])
list is a delimter-separated list of strings, which can be object
numbers, attributes, or arbitrary words. eval is a string that is to be
evaluated once for each item in list, replacing the special symbol ## with
the corresponding item from list, and the symbol #@ with the position
within the list being iterated. A space-separated list of the results
of these evaluations is returned to the caller. The effect is very similar
to @dolist, except that the results are made into a list and returned, not
executed.
Examples:
> say iter(This is a test,strlen(##))
You say "4 2 1 4"
> say iter(This is a test,{strlen(##)})
You say "4 2 1 4"
> say iter(lnum(10),mul(mul(##,##),10))
You say "0 10 40 90 160 250 360 490 640 810"
> say iter(lcon(me),[name(##)]..[money(##)])
You say "test..1 t1..1 radio..1 The Wizard's Pointy Hat..1"
> say iter(Was it a cat I saw,[words(##)] #@,s)
You say "1 1 4 2 1 3"
See also: @dolist, list(), parse().
Richard Powell
Mux Alias: Virus
2796 Wizard Staff
64.89.10.1 port 2796
Rich@gigdev.com |
|
|
|
Castaway GURU
Joined: 10 Oct 2000 Posts: 793 Location: Swindon, England
|
Posted: Thu Feb 13, 2003 9:29 am |
We 'all' dont know anything about Muxes and Mushes, at least, I dont.. So you shouldnt assume we have a clue..
Having said that, no, there is no equivalent command. The nearest you can get is using #FORALL @list {}, which loops through a list and sets %i to each item, which can then be used in the commands in {}.
You could try and create your own, using #FUNCTION and #FORALL.
I'm guessing something like:
#FUNCTION iter
{
#VAR answer "";
#FORALL %1
{
#VAR item %replace(%2, ##, %i);
#ADDITEM answer, %eval(@item);
}
@answer;
}
Untested!
Lady C. |
|
|
|
Virus Wanderer
Joined: 29 Jun 2002 Posts: 69 Location: USA
|
Posted: Thu Feb 13, 2003 1:53 pm |
Ohhh....I was under the impression that you couldnt use COmmands in a function. Now that i know I can that makes it a lot easier. I can just make a function and use #LOOP. Thx
Richard Powell
Mux Alias: Virus
2796 Wizard Staff
64.89.10.1 port 2796
Rich@gigdev.com |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Thu Feb 13, 2003 5:27 pm |
I was under that impression too. I can't test right now, and Castaway did mention that the script was untested so, Virus, does it work?
Kjata |
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Thu Feb 13, 2003 6:28 pm |
It is possible to use commands in a function, but it has to be done in such a way that it returns a value. This generally means using the %exec function as a wrapper for the commands.
- Charbal |
|
|
|
Castaway GURU
Joined: 10 Oct 2000 Posts: 793 Location: Swindon, England
|
Posted: Thu Feb 13, 2003 9:54 pm |
Having looked at the help for #function as I wrote that, I couldnt find any indication of how it knows what to return, and assumed (!) that it just returns the last value mentioned. (Which would be my @answer list)..
Terrible help page that.. If it needs a complete internal function (no idea why it should) then you'll have to be clever with %eval/$exec as Charbal said.
Sorry for any confusion :)
Lady C. |
|
|
|
|
|