At 12:27 PM -0700 6/4/06, Rasmus Lerdorf wrote:
>tedd wrote:
>>But, what brothers me about the routine, is that is DOES print "z" where it 
>>is supposed to. In other words, the characters a-z are output before 
>>continuing with aa and so on. The operation doesn't end with "z".
>
>Your condition for the loop to continue is $i<="z".
>
>[1] When $i = "y" it will obviously continue because "y" < "z"
>[2] When $i = "z" it will obviously continue because "z" = "z"
>[3] When $i = "aa" it will obviously continue because "aa" < "z"

I agree with [1] and [2], but [3] is where we part company. You see, if you are 
right, then "aaa" would also be less than "z", but that doesn't appear so.

>It doesn't stop until you get to "z"+something.  As in "za" because at that 
>point "za" > "z" so the last thing you see is the one before "za" which would 
>be "yz".

See above -- plus, I would expect that in evaluating a character, that 
character(s) would not enter the mix. If I was to evaluate a single digit, it 
would seem odd if double digits were allowed in that evaluation.

>>Here's another way to look at it. All characters before "z" are less than "z" 
>>-- correct? So, what value are all characters after "z" (i.e., "aa-yz")? They 
>>cannot be greater than, nor can they be less than. So, what are they?
>
>But you are not comparing things in the same context here.  Strings are 
>naturally compared alphabetically while you are thinking they are compared 
>numerically somehow.  Think of sorting a set of words.  Would you expect "aa" 
>to sort before or after "z" ?


Not meaning to infer that you don't know this, because I know you do -- so I 
must be confused.

Yes, it is my contention that strings are numerical -- you don't store "A" in 
memory, you store 0100 001, or ASCII DEC 65.

Likewise "a" is DEC 97 (0110 0001) and "z" is DEC 122 (0111 1010) and if I 
compare "a" to "z" , it will always be less by numeric definition.

However, if I compare "aa" with "z", then what? Is the numerical translation of 
the strings --

0110 0001 0110 0001 < 0111 1010

equal to TRUE -- I don't think so.

Likewise, is the string "aaa"" greater than "z" -- yep, I can buy that. But, if 
you hold that "aa" is less than "z", then everything must be less than "z" 
(except z stuff). So, the loop would continue until you hit the maximum 
allowable for strings -- that doesn't sound good.

I can't see the logic that says "aa" is less than "z" while "aaa" is greater. 
That sounds like something our government would dream up.

>So yes, like I said, it is a bit of a quirk, but there is no good answer to 
>what "z"++ should be and we certainly don't want to change the default 
>comparison mechanism to not compare strings alphabetically because that would 
>screw up all sorts of stuff including usorts and peoples' expectations.  It's 
>just in this case where you have gotten it into your head that incrementing 
>strings is a good thing to do.

Oh, I'm not saying to change anything. I've seen and worked with worse.

>You'd be much better off with a range call to quickly generate a range of 
>characters.  You could then loop through that character by character.  Or use 
>the chr() function to work with character codes instead.

I figured a way around it, I just thought it was odd.

Thanks for your insight.

tedd
-- 
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to