dictionary of operators

Robert Bossy Robert.Bossy at jouy.inra.fr
Fri Feb 15 10:27:26 CET 2008


A.T.Hofkamp wrote:
> On 2008-02-14, rbossy at jouy.inra.fr <rbossy at jouy.inra.fr> wrote:
>   
>> Hi,
>>
>> In the standard library module "operator", it would be nice to have a dictionary
>> mapping operators strings with their respective functions. Something like:
>>
>>   {
>>     '+': add,
>>     '-': sub,
>>     'in': contains,
>>     'and': and_,
>>     'or': or_,
>>     ...
>>   }
>>
>> Does such a dictionary already exist? Is it really a good and useful idea?
>>     
>
> How would you handle changes in operator syntax?
> - I have 'add' instead of '+'
> - I have U+2208 instead of 'in'
>   
Originally I meant only the Python syntax which shouldn't change that 
much. For some operators (arith, comparison) the toy language had the 
same syntax as Python.
Btw,  U+2208 would be a wonderful token... if only it was on standard 
keyboards.

> I don't think this is generally applicable.
>   
Thinking about it, I think it is not really applicable. Mainly because 
my examples were exclusively binary operators. What would be for unary 
operators? Or enclosing operators (getitem)?

> Why don't you attach the function to the +/-/in/... token instead? Then you
> don't need the above table at all.
>   
Could be. But I prefer settling the semantic parts the furthest possible 
from the lexer. Not that I have strong arguments for that, it's religious.

Anyway, thanks for answering,
RB



More information about the Python-list mailing list