Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: 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!! Very Happy
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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)
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: Mon Jul 21, 2003 9:38 am   
 
Yes you can. At least I managed to, and this thread here says you can:
http://www.zuggsoft.com/forum/topic.asp?TOPIC_ID=10507&SearchTerms=%23FUNC
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: 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)
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: 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.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: 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)})}
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: 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...
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: 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.
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: Tue Jul 22, 2003 12:17 am   
 
A fine explanation. Thank you!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net