On 06 June 2006 02:35, tedd wrote:
>
> a b c ... x y z aa ab ac ... yx yy yz za zb zc ... zy zx zz aaa aab
>
> -- it's not!
Yes it is. The ++ operator generates that sequence when applied to a string,
and nothing you can say or do will alter that fact.
You're trying to treat the 2nd and 3rd elements of the for () statement as an
integrated unit, but they're not - the 2nd element generates the elements of
the sequence in whatever order it generates in, and the 3rd element simply
applies a test to the generated values and causes the sequence to stop the
first time the test fails -- it's not in any way a limiter for what values will
be generated.
Using simple integers, I could code something like this, which would exhibit
similar properties:
for ($i=0; $i=($i+7)%100; $i<99)
The expression $i=($i+7)%100 is a generator for all integers in the set
[0,100], but in a non-linear order; the test $i<99 will cause the loop to stop
part way through the generated sequence, before some of the values which would
satisfy the test have been produced.
> You can't say that "a" and "aaa" are members of a set
> identified as < "z" and then step through all the members of
> that population (an infinite group) and not include "aaa" --
> UNLESS -- you arbitrarily determine an end point for a much
> smaller sub-set.
See argument above: you're not stepping through all members of the set < "z" --
or even, as in the original loop, <= "z" -- you're stepping through all members
of the set of strings containing any number of the characters [a-z] in any
combination, in the order defined by the ++ operator, and terminating on the
first generated element which is *not* <= "z". There's nothing in there that
says you have to generate *all* strings <= "z" before terminating -- just that
you stop on generating one that isn't.
> Now, unless, there is something that I don't see, which
> certainly could be the case, then php designers could have
> just as easily ended the loop at "z" and dispensed with this
> quirk all together.
Well, if the quirk were eliminated by making "z"++ be the next character in the
ASCII sequence, the loop would still not end at "z" -- it would end on
encountering "{" (if I remember my ASCII correctly).
> Besides, what's the point of having 676 character between a
> and z? Is there one?
No. And there aren't. There are 676 *strings", of length 1 and 2, as generated
by the ++ operator.
You have to remember that there is no such type as 'character' in PHP -- just
strings of length 1. And strings don't (necessarily) behave like characters.
> But this is the way it is and I except that -- but as Dirty
> Harry once said "A man's got to know his limitations" -- this
> not only applies to men and programmers, but also for
> languages as well.
>
> For example, the Unicode issue was raised during this
> discussion -- if php doesn't consider the numeric
> relationship of characters, then I see a big problem waiting
> in the wings. Because if we're having these types of
> discussions with just considering 00-7F characters, then I
> can only guess at what's going to happen when we start
> considering 000000-FFFFFF code-points.
Well, the PHP manual says: "Note that character variables can be incremented
but not decremented and even so only plain ASCII characters (a-z and A-Z) are
supported." If that continues to be the case, then the Unicode argument may be
moot.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php