|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Tue Jun 15, 2010 4:53 pm
[3.19d] %numwords() changed to something buggy (I think) |
I have a function that removes empty spaces in a text received from the mud as it is always full of extra spaces in between the words. The functinon is shown below. Hovever, after upgrading the function doesn't work any more and I think the reason for this is that the %numwords() function produces an incorrect result. Let's take an example:
Code: |
#SAY %numwords("a misshaped oaken box") |
What will it say? It says 8, but I would think it should say 4 instead. It seems the function cannot handle multiple delimiters very well any more.
Code: |
<func name="innerTrim" id="303">
<value>$words = %numwords($string)
$currentIndex = 2
$newString = %word($string, 1)
#LOOP $words-1 {
$currentWord = %word($string, $currentIndex)
#IF ($currentWord != "") {
$newString = %concat($newString, " ", $currentWord)
}
#ADD $currentIndex 1
}
#RETURN $newString</value>
<arglist>$string</arglist>
</func>
|
[/code] |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Jun 15, 2010 5:08 pm |
Confirmed. Definitely a bug and added to the bug list.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Tue Jun 15, 2010 5:39 pm |
The function has never varied in its operation since it was introduced in ZMud. If you ever got a result different than 8 using your #SAY example, it was due to a bug elsewhere in CMud that was mistakenly collapsing extra whitespace in a literal string prior to the string being sent to %numwords(). Implicitly taking advantage of these things is bad practice.
Both %numwords() and %word() allow the user to specify the delimiter. Being old zmud-era functions, this means you are limited to literal strings so there's no way to use something dynamic like, say, the %s wildcard. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Jun 15, 2010 5:44 pm |
Wow, Matt is right! I just tried the above command in v2.37 and also got the "8" result.
Hmm, still wondering if it's possible to fix given how the new json parser works. I might have a chance and I could definitely see how it would be useful.
But yeah, I'm definitely interested in knowing what version of CMUD you were using where:
Code: |
#SAY %numwords("a misshaped oaken box") |
gave a result other than 8. And thanks to Matt for pointing out that this isn't some new bug in my new table code. |
|
|
|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Tue Jun 15, 2010 6:00 pm |
Well the function I gave in my first post is supposed to trim white space from strings and this worked just before I upgraded from 3.17 (I think - forgot precise version number), but now it produces a quite silly result.
Previous result: "a misshaped oaken box"
Current result: "a misshaped a a a a a a"
I'm almost insulted by Matt's comment on bad practice. I cannot tell if something works because it's buggy or because it's well written. And I don't think it's important when this bug was introduced as long as we can agree that the current behavior is neither logical or desired... |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Jun 15, 2010 7:07 pm |
Quote: |
And I don't think it's important when this bug was introduced |
Yes, it *does* matter. If you had taken the time to catch up on recent Beta Forum posts (which you are required to do if using a BETA version of CMUD), then you would have seen that a *lot* of changed have been made recently to table and list functions and I am producing a new update almost every day. So right now it is very important for me to know if a bug is something new caused by a recent update, or something old.
In your post, you should have been clearer and just given the example of what your function did in 3.17 and what it did that was different in 3.19 (which you did in your last post above). Rather than jumping to conclusions about %numwords.
In the case of %numwords, while what you said was logical, it isn't logical if you look at this a bit differently: a space is just a delimiter character. Instead of using spaces, what if your string used comma characters instead. For example:
#SAY %numwords("a,misshaped,,,oaken,,,box", ",")
OK, now what result do you expect? Obviously you'd expect 8 in the above case. So why should it be different with spaces? What you are asking is that CMUD change it's behavior depending upon exactly which delimiter character you are using. Should spaces be compacted and treated as a single delimiter? What about other delimiter characters, such as a CR or newline?
Then there is the compatibility issues. I checked zMUD and it does give 4 as the result for your %numwords example. But the CMUD 2.37 public version returns 8. So how many people have written their CMUD scripts to use the new result of %numwords? Can I just arbitrarily change how %numwords handles spaces and potentially break existing CMUD scripts? Or maybe it should be changed so that imported zMUD scripts work the same as zMUD?
All I'm saying is that this issue is far from simple. So please don't complain about Matt who is just trying to help.
Back to your script. If you actually play around with it to try and pin down the problem (which is another requirement of being a beta tester and using beta versions), then you would soon discover that the bug has nothing to do with %numwords or anything else like that. The bug is actually something new with the #ADD command. If you replace your:
Code: |
#ADD $currentIndex 1 |
with
Code: |
$currentIndex = ($currentIndex + 1) |
then it works. So that's the actual bug and that's what I'm adding to the bug list.
I found the above problem by simply putting a #SHOW line in your script to print out the value of $currentWord and $currentIndex. Basic debugging practice. |
|
|
|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Tue Jun 15, 2010 8:49 pm |
You seem to have high demands towards your beta testers - you could also just say thanks for reporting. Perhaps I didn't hit right on the spot but I did lead you to a bug in CMUD which apprantly none of the other beta tester found.
What I didn't like about Matt's comment was that he insinuated that I was deliberately abusing a bug in a manner that suited me which not only was wrong but also not a very nice thing to say even if it wasn't.
Back on the track: I'm not sure that I find it so obvious that there should be 8 words in the example below but I guess it depends what you expect from the function and this might not be clear. The thing I would expect is actually that it produces the amount of words found and not just counting delimiters and adding one as you seem to suggest could be a fair interpretation.
Code: |
#SAY %numwords("a,misshaped,,,oaken,,,box", ",") |
How about this: How many lines do you see below?
Code: |
Line 1
Line 2
Line 3
|
Last thing: What I mean about if it matters or not is that I am reporting something I find to be a bug. To me it's not so important if it's 2 days or 10 years old - I just want to show that I found something strange. For you of course it can be important but I hope you will not ignore bugs just because they are old.
EDIT: Thanks for the solution by the way. I'll replace the buggy line. |
|
|
|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Tue Jun 15, 2010 9:10 pm |
I see four (lights). :P
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Jun 15, 2010 9:48 pm |
Yep, I see four lines in your above example. Also, if you import "a,misshaped,,,oaken,,,box" into Microsoft Excel as a comma-separated file, you get 8 columns. So CMUD is treating delimiters correctly as far as I'm concerned right now.
Quote: |
For you of course it can be important but I hope you will not ignore bugs just because they are old. |
I don't ignore bugs just because they are old. But I've got 200+ "old bugs" already on my bug list and for the past week or so I've been more concerned about fixing new bugs that are caused by the complete rewrite of the stringlist/table code.
Turns out the problem with #ADD was related to the other big recent change which is how variable storage is optimized to speed up variable changes (replacing the old #NOSAVE option). This caused a bug in the #ADD routine.
What I think me and some of the others in the forum are complaining about with your posts is that you seem more interested in playing your MUD with a Beta version rather than acting as a proper Beta Tester. This violates the terms that you agreed to when you downloaded the Beta version. But I think we've already covered that in the other thread.
Yes, I do have a high demand for beta testers. Otherwise I'd be doing all of this as a closed beta with only people who are willing to follow the policies. In that scenario you would still be using v2.37. The perks you are getting for beta testing are being able to use a newer version with (sometimes) fewer bugs and more features, and I'm not requiring beta testers to pay the upgrade fee for the beta. These perks are not free. They require you to follow the beta testing procedures.
It wasn't about whether it was old or new bug, it was about having you spend the extra 2 minutes yourself to try and determine what part of your script was causing the problem so that you can save me time and allow me to get more bugs fixed. And that's all about the basic attitude of whether you are posting here to try and help *me*, or just trying to help yourself play your MUD. |
|
|
|
Nezic Apprentice
Joined: 10 Oct 2000 Posts: 119 Location: Colorado
|
Posted: Tue Jun 15, 2010 11:38 pm |
If possible/feasible, I would suggest adding an option that allows the user to 'skip' empty delimiters.
For example, when importing data into Excel, the option checkbox for this is labeled "Treat consecutive delimiters as one".
I think this would be a very useful feature, and to me seems to be the more 'natural' way for something that counts words (Like the 'Count Words' feature in word processors). |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Jun 16, 2010 12:29 am |
Yep, adding an option like that is what I'll need to do with this. That's the only way to avoid breaking existing scripts and still allow the new functionality. This is on the to-do list for a future version, but probably not for the next public release.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Jun 16, 2010 12:57 am |
I suppose in a manner similar to %subregex(), perhaps instead of adding more preferences/properties or optional arguments you could just allow wildcards to be included in the delimiter string? Even if just limited to a subset of the simpler ones (ie, %letter), something like:
#say %numwords("a really spaced out phrase",%s)
might go farther in terms of backwards compatibility (that may or may not be dependant on the way CMud works rather than on the way ZMud worked) while still allowing for easy Compatibility Report types of fixes like what kjaerhus is running into. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Jun 16, 2010 1:03 am |
Perhaps, although the idea of allowing *any* wildcard or regular expression is too scary to think about. However, maybe I'll just support "%s" as a single special case to deal with "multiple white space".
|
|
|
|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Wed Jun 16, 2010 4:58 pm |
Zugg wrote: |
Yep, I see four lines in your above example. Also, if you import "a,misshaped,,,oaken,,,box" into Microsoft Excel as a comma-separated file, you get 8 columns. So CMUD is treating delimiters correctly as far as I'm concerned right now. |
Hehe, I really didn't look for an answer though - I was just trying to make a point that the right answer depends on the view you take. To me the function name numwords means that I get the number of words in the string. I am not so interested in how many words there could have been as determined by the number of delimiters. If you were looking at a parking lot with white lines as "delimiters" and I asked you how many cars were present I don't suppose you would tell me the number of lots but rather the actual numbers of cars present...
To add to my case a class like StringTokenizer in Java will say 4 words in "a misshaped oaken box" no matter how many spaces in between the words. Anyway, I don't think it's the most important thing to fix right now so no need to use more time on it. You may consider simply replacing the function later on with one called countwords or something like that and either let the old one stay for compatibility reasons or make another function with a more meaningful name and force people to choose the one of their liking.
Zugg wrote: |
What I think me and some of the others in the forum are complaining about with your posts is that you seem more interested in playing your MUD with a Beta version rather than acting as a proper Beta Tester. This violates the terms that you agreed to when you downloaded the Beta version. But I think we've already covered that in the other thread.
Yes, I do have a high demand for beta testers. Otherwise I'd be doing all of this as a closed beta with only people who are willing to follow the policies. In that scenario you would still be using v2.37. The perks you are getting for beta testing are being able to use a newer version with (sometimes) fewer bugs and more features, and I'm not requiring beta testers to pay the upgrade fee for the beta. These perks are not free. They require you to follow the beta testing procedures.
It wasn't about whether it was old or new bug, it was about having you spend the extra 2 minutes yourself to try and determine what part of your script was causing the problem so that you can save me time and allow me to get more bugs fixed. And that's all about the basic attitude of whether you are posting here to try and help *me*, or just trying to help yourself play your MUD. |
Thing is that my function broke and as I quickly found the "bug" in numwords I was sure that this caused the fault. Therefore I wrote this post about the numwords problem. The fact that this was not causing my problems doesn't mean that my entire argument about numwords falls.
Problem about what version you choose is really that you stopped doing anything to the public version 1½ years ago and that way you practically force CMUD subscribers to use the beta if they have any problems with the public versions. I think you should appreciate input also from people who don't spend two days digging into the problem before posting. The other way around I do appreciate very much that I get your response to most of my posts although I often find it hard to convince you that there might be a problem in the cases where it's hard for me to prove. Even when other experienced users say that there might be a problem like in the case of duplicating variables. |
|
|
|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Wed Jun 16, 2010 5:16 pm |
Zugg wrote: |
It wasn't about whether it was old or new bug, it was about having you spend the extra 2 minutes yourself to try and determine what part of your script was causing the problem so that you can save me time and allow me to get more bugs fixed. And that's all about the basic attitude of whether you are posting here to try and help *me*, or just trying to help yourself play your MUD. |
Point taken though. |
|
|
|
|
|
|
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
|
|