Re: Array of functions, Pythonically

2008-02-25 Thread Paul McGuire
On Feb 25, 11:53 am, [EMAIL PROTECTED] wrote: > >  { '+': operator.add, '-': operator.sub, ... } > > Then EXPR OPER EXPR -> ops[ OPER ]( EXPR, EXPR ), right? I think this is the most Pythonic idiom. You can even define your own custom binary operators, such as '$' to convert dollars and cents to

Re: Array of functions, Pythonically

2008-02-25 Thread castironpi
>  { '+': operator.add, '-': operator.sub, ... } Then EXPR OPER EXPR -> ops[ OPER ]( EXPR, EXPR ), right? -- http://mail.python.org/mailman/listinfo/python-list

Re: Array of functions, Pythonically

2008-02-25 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > My parser has found an expression of the form CONSTANT_INTEGER > OPERATOR CONSTANT_INTEGER. I want to fold this into a single > CONSTANT_INTEGER. > > The OPERATOR token has an intValue attribute, '+' == 0, '-'== 1, etc. > In C I'd put functions Add, Subtract, ... into

Re: Array of functions, Pythonically

2008-02-25 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > My parser has found an expression of the form CONSTANT_INTEGER > OPERATOR CONSTANT_INTEGER. I want to fold this into a single > CONSTANT_INTEGER. > > The OPERATOR token has an intValue attribute, '+' == 0, '-'== 1, etc. > In C I'd put functions Add, Subtract, ... into a