Adding print-style function calls, and preproc plugins

Bengt Richter bokr at accessone.com
Thu Aug 30 19:04:24 EDT 2001


On Thu, 30 Aug 2001 09:39:21 +0200, "Alex Martelli" <aleax at aleax.it> wrote:

>"Gerson Kurz" <gerson.kurz at t-online.de> wrote in message
>news:3b8dc97b.60293093 at news.isar.de...
>    ...
>> There might be a slight ambiguity when function names are used without
>> arguments, because it then could be interpreted as either the function
>> object or the function call; but then again, I see writing the
>> function name as object without assigning it to some variable or some
>> such as rather pointless.
>
>And of course there's no problem interpreting whether:
>
>    blobber plikke
>
>means:
>
>    blobber(plikke)
>
>or:
>
>    blobber(plikke())
>
>is there?  I mean, it just takes some mindreading on the
>part of the compiler, interpreter AND human reader, that's
>all -- they'll just have to know or guess whether plikke
>names a function (or other callable object) and in that
>case whether it's "pointless" or "indispensable" for the
>plikke object itself to be passed in as the argument to
>blobber -- as opposed to its being called and the RESULT
>of the call passed as blobber's argument.  Piece of cake.
>
I'm sure it's important, not pointless, to be able to
distinguish access to a function as object from access as
a call, but one could conceive of more than one way to
be explicit. Tacking on () is one way.

For the sake of argument, playing devil's advocate, you could
make yourself a preprocessor which would recognize particular
function names from a list you supply, and if the name of such
a function appeared as the first white-space-delimited thing
on a line, it would put parens around the rest of the line and
substitute that, so
    foo x
would become
    foo(x)
and you would explicitly have determined what was going to happen.
(If you try to rebind foo, you're responsible if you put white
space between foo and the '=' ;-)

BTW, it might be interesting if symbols existed as objects that
could be returned by a function on the left hand side of '='
so that
    def foo()
        return symbol('xxx')
    ...
    foo() = 'yyy'
would result in
    >>> xxx
    'yyy'
and foo would remain bound to the function.




More information about the Python-list mailing list