Other notes
Bengt Richter
bokr at oz.net
Wed Dec 29 23:46:25 EST 2004
On Thu, 30 Dec 2004 03:37:38 GMT, Andrew Dalke <dalke at dalkescientific.com> wrote:
>Bengt Richter:
>> OTOH, there is precedent in e.g. fortran (IIRC) for named operators of the
>> form .XX. -- e.g., .GE. for >= so maybe there could be room for both.
>
>> Hm, you could make
>>
>> x .infix. y
>
>
>> x .op1. y .op2. z => op2(op1(x, y), z)
>
>The problem being that that's already legal syntax
D'oh ;-)
>
>>>> class Xyzzy:
>... def __init__(self):
>... self.op1 = self.op2 = self.y = self
>... self.z = "Nothing happens here"
>...
>>>> x = Xyzzy()
>>>> x .op1. y .op2. z
>'Nothing happens here'
>>>>
Ok, well, that's happened to me before ;-)
We'll have to find a way to make it illegal, but it's not likely to be quite as clean.
x ..OP y
x ./OP y
x .<OP y
x .<OP>. y
X ._OP_. y
x ..OP.. y # for symmetry ;-)
X .(OP). y # emphasizes the .expression. returning a function accepting two args
That might be the best one.
OTOH some time ago I was thinking of .(statements). as a possible tokenizer-time star-gate into
a default-empty tokenizer-dynamically-created module which would essentially exec the statements
in that module and return the value of the last expression as a string for insertion into the token
source code stream at that point being tokenized.
Thus e.g. you could have source that said
compile_time = .(__import__('time').ctime()).
and get a time stamp string into the source text at tokenization time.
I had also thought obj.(expr) could be syntactic sugar for obj.__dict__[expr]
but that would also interfere ;-)
So maybe .(OP). should for infix, and .[stargate exec args]. should be for that ;-)
Regards,
Bengt Richter
More information about the Python-list
mailing list