On 14/03/2015 16:33, Rustom Mody wrote:
On Saturday, March 14, 2015 at 9:45:10 PM UTC+5:30, Chris Angelico wrote:
On Sun, Mar 15, 2015 at 2:59 AM, Rustom Mody wrote:
Causing all sorts of unnecessary confusions:
An int-function returns int and a char*-functions returns char*.
Does a void-function return void??
No a void function doesn't return anything!
Ah So a void function does a longjmp?

All of which is to say that in retrospect we need (at least in imperative 
programming) procedures and functions.

Best if the language supports them

Python has a broad concept of "functions/methods that return something
interesting" and "functions/methods that always return None". (The
distinction often corresponds to non-mutator and mutator methods, but
that's just convention.)

With due respect Chris, you are confused:

Sure any effective *pythonista* (who writes useful python) will have this 
concept.

Python (as against pythonistas) has no such conceptĀ¹ as "function that ALWAYS
returns None"

Consider this foo

def foo(x):
...  if x>0: return x-1
...
foo(3)
2
foo(-1)


As best as I can see python makes no distinction between such a foo and
the more usual function/methods that have no returns.
You can I can talk about these and distinguish them
Python has no clue about it.


Python *ALWAYS* returns None for any path through a function that doesn't specify a return value. Taking your example.

>>> def foo(x):
...     if x>0: return x-1
...
>>> import dis
>>> dis.dis(foo)
  2           0 LOAD_FAST                0 (x)
              3 LOAD_CONST               1 (0)
              6 COMPARE_OP               4 (>)
              9 POP_JUMP_IF_FALSE       20
             12 LOAD_FAST                0 (x)
             15 LOAD_CONST               2 (1)
             18 BINARY_SUBTRACT
             19 RETURN_VALUE
        >>   20 LOAD_CONST               0 (None)
             23 RETURN_VALUE

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to