Implicit lists

Bengt Richter bokr at oz.net
Sun Feb 2 20:00:21 EST 2003


On Sun, 02 Feb 2003 05:18:47 +0100, Christian Tismer <tismer at tismer.com> wrote:
[...]
>The summary is this:
>How can I express that I want to pass a string or some other
>object as a single parameter to a function that both accepts
>singletons and sequences? How can I prevend that Joe User
>ignores my interface and passes a string, and I misinterpret
>it as a bunch of characters?
>
>No solution so far was sufficient.
>All the attempts to figure out what the user wants
>have side effects, put implications or restrictions
>on objects which aren't intuitive or are application
>specific. I.E., At my taste, I would never accept an
>array.array as a multiple argument, but others might.
>
>Python's flexibility is great. At the same time, it is
>its own enemy. I can have atomic objects, lists, tuples
>and general sequences, and I can pass them to functions
>which accept atoms, lists, tuples and sequences, but there is
>no way to tell the function whether I meant to pass something
>like an atomic object or like a sequence.
>
>Is the consequence to always try to avoid polymorphic interfaces,
>or do we need a new construct to express our intent?
>I could imagine an inquiry function that would yield such information,
>and in the case of strings, this would say "treat me as an atomic".
>
I can see inquiry functions, but then there has to be a default inquiry
method or a default when there is none. CORBA and COM type things come
to mind. But "treat me as atomic" also reminds me of (quote x) or 'x.
IOW, maybe there could be a quote-with-respect-to-serial-decomposition
that could generally wrap anything and be recognized and unquoted once
by anything looking for a sequence.

Just a thought, not explored very far ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list