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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Thu Nov 15, 2007 11:23 pm   

A few nifty functions for lists
 
These all require CMud v2.11 or better since they are actual functions and use some new commands. I have been trying to come up with a way to do the subset better, and short of doing delset(delset) I haven't had a good thought, so let me know if you have one. Currently they use a '๗' to surround list items, this is done so that a list item that would be a part of another list item isn't used. I chose that character because it looks cool and isn't anywhere in the lists I am working with. You can change it to another if you like. These were based around regexes for maximum speed and tend to clock in at 0ms on my system with a small sized list and set.
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<cmud>
  <func name="delset">
    <value>$llist=%concat("๗",%replace($list,"|","๗๗"),"๗")
$lpat=%concat("(๗",%replace($set,"|","๗|๗"),"๗)")
$lret=%leftback(%right(%subregex($llist,$lpat,""),1),1)
#RETURN %replace($lret,"๗๗","|")</value>
    <arglist>$set,$list</arglist>
  </func>
  <func name="issubset" type="Integer">
    <value>$llist=%concat("๗",%replace(%dups($list),"|","๗๗"),"๗")
$lpat=%concat("๗",%replace($set,"|","๗|๗"),"๗")
#IF ($exact) {
 $lpat=%concat("(?:(?:",$lpat,")(?:(?!",$lpat,")๗.*?๗)*){",%numitems($lpat),"}")
} {
 $lpat=%concat("(?:",$lpat,")")
}
#RETURN %regex($llist,$lpat)</value>
    <arglist>$set,$list,$exact</arglist>
  </func>
  <func name="subset" type="StringList">
    <value>$lret=""
#FORALL $set {
 #IF (%ismember(%i,$list)) {#ADDITEM $lret {%i}}
}
#RETURN $lret</value>
    <arglist>$set,$list</arglist>
  </func>
</cmud>

When the issubset's exact argument is true then all items of the set must occur in the list like doing ismember and ismember... When false only one needs to be found which makes it like doing ismember or ismember...
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Fri Nov 16, 2007 1:20 am   
 
Did you forget the part where you tell us what they do or are we supposed to guess from the names, or work it out from the code? Wink
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Fri Nov 16, 2007 2:20 am   
 
Well I guess I did forget to mention what 2 of them do. 1 I described kind of backasswardly. I guess a proper description for all 3 is order.

@issubset(set,list,exact)
Returns 0 if the items of the list set are not members of the list list, non-zero otherwise. If exact is true then all items of set must be present in list to cause a non-zero return.

@subset(set,list)
Returns a list of all items from the list set that occur in the list list.

@delset(set,list)
Returns a list of all items from the list list that did not occur in the list set.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Fri Nov 16, 2007 3:30 am   
 
Much better! Very Happy Yeah, these are nifty!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Nov 19, 2007 2:24 pm   
 
Wouldn't it be better to use the proper set mathematics terms, Union and Intersection?
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Mon Mar 02, 2009 12:55 am   
 
delset isn't working for me at the moment, anyone else have this problem?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Mon Mar 02, 2009 11:59 am   
 
If you got the code from the forum then it won't work. The most recent changes in the forum hosting system have caused it to replace the special character I was using with HTML codes that are then stripped. I would suggest getting my package from the library for the correct and most recent versions of these functions.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Tue Mar 03, 2009 5:45 pm   
 
The package from the library has "&#xF7;" as its replacement, should this be a "รท"? A lot of the scripts where you do this kind of replacement I see showing up as the &#xF7;.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Tue Mar 03, 2009 10:41 pm   
 
Yeah that would be it. Mostly it is just about having a seperator that won't interfere with normal CMud workings. At some point I will go back through all the code in that package looking for better ways, just not anytime soon.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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