Thoughts on new grammar rules (PEP 284 in particular)
Steve Horne
steve at lurking.demon.co.uk
Tue May 14 07:56:23 EDT 2002
On Fri, 10 May 2002 11:00:36 -0700, David Eppstein
<eppstein at ics.uci.edu> wrote:
>In article <82undu4anb47usgck50ebil2ku1f36173q at 4ax.com>,
> Steve Horne <steve at lurking.demon.co.uk> wrote:
>
>> I was just reading PEP284 and, in general, I like it. The trouble is,
>> I'd quite like these limit-specifications to be more general. For
>> example, I'd quite like to write...
>>
>> if 0 <= x < 10 :
>> print "x is in range"
>>
>> There is a big problem with this, of course - this is already legal
>> Python, but the semantics aren't what I intend.
>
>I don't understand your point -- what semantics do you intend for this
>test that are different from current Python?
That was actually a mistake - I use C++ more than Python and stupidly
did not test this before assuming C-like semantics.
In C...
x = 15
0 <= x < 10
= (0 <= x) < 10
= 1 < 10
= 1
which is not what is intended. Note - I did not check the
associativity of these operators, but the principle is correct - the
result would not be a two-ended range check.
Unfortunately for my argument, Python does 'the right thing' already.
--
Steve Horne
steve at lurking.demon.co.uk
More information about the Python-list
mailing list