PyWart: The problem with "print"

R

rusi

I am aware of what it means, but Python doesn't really have it (although
it may evolve to it with annotations).
No polymorphism huh?
py> len([1, 2, 3])  # len works on lists
3
py> len((1, 2))  # and on tuples
2
py> len({})  # and on dicts
0
py> len('I pity the fool')  # and on strings
15
py> len(b'\x23')  # and on bytes
1
py> len(set(range(2)))  # and on sets
2
py> len(frozenset(range(4)))  # and on frozensets
4
py> len(range(1000))  # and on range objects
1000
Okay, wow, it looks like we need to define some new computer science
terms here.

Fairly definitive terms have existed since 1985:http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf


You are making an "outside view of a function" (until a better term is
found).  So that give you one possible view of polymorphism.  However,
*within* a class that I would write, you would not see polymorphism
like you have in C++,  where it is within the *function closure*
itself.   Instead you would see many if/then combinations to define
the behavior given several input types.  I would call this simulated
polymorphism.

Cardelli and Wegner cited above call this ad-hoc polymorphism.
What you are calling polymorphism, they call universal polymorphism.

See sect 1.3 for a summary diagram

I should have added that python has the universal polymorphism that
you want:

$ python
Python 2.7.5 (default, May 20 2013, 13:49:25)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
len([1,2]) 2
len([[1,2]]) 1
len([[[1,2]],[[3]],[[4,5]]]) 3

The main thing to note about universal -> parametric polymorphism is
that one definition works for an infinite set of types, without any
extra code(ing)
 
M

Mark Janssen

You really need to stop commenting when you clearly have no
understanding of what you're talking about.

"Clearly", okay. You've added a wee bit of constructive argument *if*
you're considered reputable to the rest of the list; however,
"polymorophism", should really only be considered "true" when
specifically in a "functional enclosure". C++ has this, through it's
type system, more strictly when there is no references to variables
outside the function scope. Python does not.

But this all relates to theoretical ObjectArchitecture and
ModelsOfComputation that aren't well-understood outside a few
specialized folks. Good luck trying to work through the chaff, if you
don't want to know the difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top