Adding print-style function calls, and preproc plugins

David Bolen db3l at fitlinxx.com
Thu Aug 30 14:54:32 EDT 2001


Gerson.Kurz at t-online.de (Gerson Kurz) writes:

> Well please remember what my original intent was: writing my own print
> function - er - statement. So, is "print e2 e3 e4 e5" a valid statement ?
> No. Is "print e2,e3,e4,e5" ambiguous ? No. So what is the problem?

Why wouldn't the second case be ambiguous?  If e2, e3 etc.. are
callable functions, are you trying to print the result of calling e2
etc.. or are you trying to print the __str__ of the object that e2 is
referencing?  Remember also that an arbitrary object in Python may be
made callable, so the __str__ may in fact be more detailed information
than just <function e2 at #####>, for example:

    >>> class Callable:
    ...   def __call__(self):
    ...     return 10
    ...   def __str__(self):
    ...     return "Special stuff"
    ...
    >>> c = Callable()
    >>> print c
    Special stuff
    >>> print c()
    10

Now, what should the first "print c" do under your suggestion?  Either
possibility is valid - that's ambiguous :-)

> I was quite astonished about how strongly people seemed to react to that
> idea. Please, my problem was that I had to modify print's behaviour, and
> couldn't do so, because by going from "print" to a function, you have to
> enclose the arguments in brackets.

But that wasn't how you phrased your original proposal.  Although you
may have been thinking about a print equivalent (e.g., a very limited
type of function and usage of that function), you wrote:

  "... Wouldn't it be nice if you *could* call your "normal" functions
  in the same way [as print]? ..."

which is far more general, and as has been pointed out a far more
ambiguous suggestion than you seemed to realize in your original post.
But as above, even the print idea is ambiguous.  I think it's that
which is creating the reaction, since most people are looking at the
further reaching impacts than just a replacement for print.

Personally I don't find the potential confusion caused by such
irregular handling of function arguments to be worth the tiny benefit
from not needing parentheses in the few statements in Python.  

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list