|
teknocide Beginner
Joined: 15 Jul 2003 Posts: 25 Location: Sweden
|
Posted: Mon Jul 21, 2003 1:00 am
Curious #FUNC-test |
Hello!
to keep it short; I have a number of string-lists containing different words. let's say that:
fruitList=banana|pear|orange
I want a function that can take the foremost item from this list, return it , and at the same time place it at the end of the list. (banana|pear|orange = pear|orange|banana = orange|banana|pear.. you get the idea)
I tried experimenting with #FUNC, but I can't get it to execute properly. My definition, for the moment, looks like:
#FUNCTION processList {#ADDITEM %1 {%exec(%pop(%1))}}
my reason for using functions is that I simply want to be able to do something like:
eat @processList(fruitList)
from within an alias. I know this could be solved with normal aliases, but if it Can be solved with functions, it would be much smoother!
____
btw, I found the edit-function now, so I will no longer multi-post in my own threads!! |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Jul 21, 2003 4:47 am |
You simply cannot use #commands within a @function(), but you're pretty much on the right track.
%additem(item-to-add, list) |
|
|
|
teknocide Beginner
Joined: 15 Jul 2003 Posts: 25 Location: Sweden
|
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Mon Jul 21, 2003 12:47 pm |
You can use %exec, but there is no need to do it in this case. Like Matt pointed out, there is a function called %additem, so you can already do it all with functions:
%additem(%pop(%1), @%1) |
|
|
|
teknocide Beginner
Joined: 15 Jul 2003 Posts: 25 Location: Sweden
|
Posted: Mon Jul 21, 2003 12:50 pm |
The problem with that solution is that %additem doesn't really add an item to the string-list; it returns the string-list with an item added, which is not what I want. I want to RETURN the foremost item from the function, and have the list "rolled" one step.
|
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Mon Jul 21, 2003 1:08 pm |
I see now. In this case you do need %exec. %exec will return whatever the contents of what it executes returns. Since commands do not return a result, you need %exec to execute something that consists of just a function call or variable reference. Here is what you need then:
#FUNC processList {%exec(%item(@%1, 1);#ADDITEM %1 {%pop(%1)})} |
|
|
|
teknocide Beginner
Joined: 15 Jul 2003 Posts: 25 Location: Sweden
|
Posted: Mon Jul 21, 2003 1:28 pm |
Thanks man, that worked great!
Although, zMUD makes me confused now.
after first glance at your function, I thought it was bugged -- a ";" in the middle of an %exec-function?
The zMUD-editor thinks the same, but it DOES execute properly..
if changed to:
#FUNC processList {%exec(%item(@1,1));#ADDITEM %1 {%pop(%1)}}
which looks more correct -- brackets-wise -- to me, the zMUD-editor thinks the function is fine, but the function doesn't function (:P) properly.
Weird, if you ask me. Why do you have to break a rule of thumbs -- by using a ";" to separate function-parameters -- to get it to work? stupid... |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Tue Jul 22, 2003 12:04 am |
The ; is not used to separate parameters, it is used normally as the command separator. %exec will execute whatever you give just as if you had typed it into an alias or the command line. The only difference is that it will also return whatever it was that what it executed returned.
The syntax checker does not like the function I gave you because it sees a ; inside a function call. To make it stop complaining (and to have it the way that is technically correct), surround all of the contents of the %exec with double quotes. |
|
|
|
teknocide Beginner
Joined: 15 Jul 2003 Posts: 25 Location: Sweden
|
Posted: Tue Jul 22, 2003 12:17 am |
A fine explanation. Thank you!
|
|
|
|
|
|