Assignment versus binding

Rustom Mody rustompmody at gmail.com
Wed Oct 5 09:03:10 EDT 2016


On Wednesday, October 5, 2016 at 12:21:35 PM UTC+5:30, Chris Angelico wrote:
> On Wed, Oct 5, 2016 at 5:19 PM, Rustom Mody  wrote:
> > Its ironical:
> > - Function in Fortran was meant to emulate math-functions
> > - C took the same thing and did a ‘small little syntax elision’ viz
> > conflating function and subprogram (procedure in Pascal speak) all under
> > the heading of function. In Pascal it was certainly a publicised intent
> > to sharply distinguish functions — no side-effects — from procedures — no return value.
> > - Finally this abuse of notation (and notions) has become such a norm (normal!)
> > that people are surprised to find non-abusive languages!
> 
> So how do you handle something that, by its nature, has BOTH side
> effects and a return value? For instance, writing to a socket has
> three results:
> 
> 1) Data is sent to the socket (side effect), possibly with consequent
> changes to visible state
> 2) Status return saying how much was written
> 3) Possible error return in the event of failure.

Not sure I understand your question.
Analogy: Take Linux syscalls

In C you do
#include <unistd.h>
And then do (say)
n = read(fd,buffer,bufsize);

In assembly you do (something like!)
mov eax, 1   # read's number
mov ebx, fd
mov ecx, buffer
mov edx, bufsize
int 0x80
mov n, eax

You could argue that they are identical
Or they are completely different... unrelated

Truth is somewhere in between; someone who knows this world would 
be able to deduce one from the other.
OTOH its hard to deny the fact that the assembly is far from the C.

Likewise here.
You cant use effectful things and say thats a function
But you can get any effects you want:
https://hackage.haskell.org/package/network-2.6.3.1/docs/Network-Socket.html

starts with this para:

| The Network.Socket module is for when you want full control over sockets. 
| Essentially the entire C socket API is exposed through this module; in 
| general the operations follow the behaviour of the C functions of the same 
| name (consult your favourite Unix networking book).

One could simulate something like this even in python by saying that
- socket is a None returning function (procedure)
- it takes a list of len 3 say arg
- which is mutated on return to contain (size, buffer, errorstate)

No its not pythonic
Its not haskellic either

Just saying that world-effects does not imply or follow from impure functions



More information about the Python-list mailing list