PyWart: More surpises via "implict conversion to boolean" (and othersteaming piles!)

C

Chris Angelico

Sometimes, it has a *lot* of implicit state:

os.fork()

os.fork() always returns 0, so it *clearly* has no state whatsoever.
It also always returns the next available PID, which is only a small
amount of extra state (from the OS). Nothing else affects its return
value!

ChrisA
 
I

Ian Kelly

Functions map a value to another value. They can be one-to-one, or many-
to-one. (Mathematically, they cannot be one-to-many or many-to-many,
that's called a relation.) What about zero-to-one?

If the function always returns the same result, e.g.:

def spam():
return "spam spam spam"

That's still one-to-one. There is no such thing as a zero-to-one mapping.

Mathematical functions map a single value to a single value. To represent
multi-argument functions then, the single input takes on the value of an
ordered sequence. The input value of a 0-argument function then is the
empty sequence.
 

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,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top