functions without parentheses

Bengt Richter bokr at oz.net
Sat Jul 30 20:42:59 CEST 2005


On Fri, 29 Jul 2005 20:54:42 +1000, Steven D'Aprano <steve at REMOVETHIScyber.com.au> wrote:

>On Fri, 29 Jul 2005 06:37:52 +0000, Bengt Richter wrote:
>
>> I suggested in a previous thread that one could support such a syntax by
>> supporting an invisible binary operator between two expressions, so that
>> examine "string" translates to examine.__invisbinop__("string") if
>> examine as an expression evaluates to an object that has a __invisbinop__ method.
>
>Why would you want to?
>
Mainly to say that I think there is way to do it (and thus further to mulch the idea garden ;-)
whatever the merits. As to the merits, I haven't thought about it much, but ISTM for limited
contexts it would allow you to spell concatenating/aggregating expressions without the
"line noise" of intervening operator glyphs, e.g.,

    agg = Aggregate() first_thing second_thing 3 "four" etc.and.so.forth ;
or

   mypath = Path() prefix middle filename+'.ext' ; # explicit terminating ';' or (...) might be needed
                                                   # if EOL can be part of whitespace delim as below

or
    arr = (ArrayElementAggregator()
             11 12 13
             21 22 23
          )


The latter presupposes that white-space including an EOL causes attempt to access an alternate
__invisbinop__ (e.g., __invisbinopNL__) that one could define to aggregate new rows of expressions,
but would not be an error if absent, and thus end a single-line aggregator without explict ';' or parens.

I haven't thought of all the ramifications, I was just playing with the idea ;-)

Others might think of other ways to answer your "why" ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list