[Pythonmac-SIG] [ann] appscript 0.4.0 released
has
hengist.podd at virgin.net
Fri Feb 13 15:46:48 EST 2004
Michael Hudson wrote:
> >>1) override the bitwise operators
> >
> > items.test((its.size > 12) & (its.color == [0,0,0])) # items whose
>> size > 12 and color = {0,0,0}
>
>This kind of thing is I'm not a big fan of operator overloading, in
>general.
Heh, I'm not a big fan of operators; know what you mean though.
Reason I'm trying it here is that a conventional method call-based
approach soon becomes unreadable when constructing an expression of
any complexity; for example:
items.test(its.size.greaterthan(12).AND(its.color.equals([0,0,0])))
versus:
items.test(its.size > 12 and its.color == [0,0,0])
> > and not:
>>
> > ref.test(its.size > 12 & its.color == [0,0,0])
>>
>> which'll cause an error when Python tries to evaluate '12 & its.color'
>> instead of '<object> & <object>'.
>
>Huh?
Python's evaluation order is to do the bitwise AND before the
comparison tests, so it sees:
its.size > 12 & its.color == [0,0,0]
as:
its.size > (12 & its.color) == [0,0,0]
instead of:
(its.size > 12) & (its.color == [0,0,0])
which is what I want it to do.
> > ref.test(
>> (its.size > 12) & (its.color == [0,0,0])
>> )
>>
>> ref.test(
>> (its.size > 12).AND(its.color == [0,0,0])
>> )
>>
> > ref.test(
>> AND(its.size > 12, its.color == [0,0,0])
> > )
>>
>
>I think I prefer something like 3), but admittedly, I haven't used
>that style for anything much...
Worth playing around with to see what feels best to you. e.g. The
third form should work quite well for users when there's only a
single logical test involved, but may not work so well for more
complex expressions, eg:
(its.size > 12 and its.color == [0,0,0]) or (its.length > 0 and
its.characters[1] != 'X') # ideal (true infix)
OR(AND(its.size > 12, its.color == [0,0,0]), AND(its.length > 0,
its.characters[1] != 'X')) # pseudo-prefix
(its.size > 12).AND(its.color == [0,0,0]).OR(its.length >
0).AND(its.characters[1] != 'X') # pseudo-infix
(Ech. Decisions, decisions... But hey; I'm just the bloke wot writes
it, youse all are the ones what gotta use it.;)
Thanks,
has
--
http://freespace.virgin.net/hamish.sanderson/
More information about the Pythonmac-SIG
mailing list