Re: Is there a way to change the closure of a python function?

2016-09-29 Thread Lawrence D’Oliveiro
On Thursday, September 29, 2016 at 7:13:15 PM UTC+13, Gregory Ewing wrote: > Philosophical question: Is a function that never > returns actually a function? Denotational semantics calls that value “bottom”. -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Steven D'Aprano
On Thursday 29 September 2016 16:13, Gregory Ewing wrote: > Philosophical question: Is a function that never > returns actually a function? Mathematically, all functions return, instantly. Or rather, mathematics occurs in an abstract environment where there is no time. Everything happens simult

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Gregory Ewing
Paul Moore wrote: What "allows side effects" in languages like Haskell is the fact that the runtime behaviour of the language is not defined as "calculating the value of the main function" but rather as "making the process that the main functon defines as an abstract monad actually happen". Tha

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Chris Angelico
On Thu, Sep 29, 2016 at 1:53 PM, Steve D'Aprano wrote: > John Cook suggests that functional programming gets harder and harder to do > right (both for the compiler and for the programmer) as you asymptotically > approach 100% pure, and suggests the heuristic that (say) 85% pure is the > sweet spot

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Steve D'Aprano
On Wed, 28 Sep 2016 07:18 pm, Chris Angelico wrote: > On Wed, Sep 28, 2016 at 6:52 PM, Gregory Ewing > wrote: >> Chris Angelico wrote: >>> >>> >>> wrote: >>> * No side effects (new variable bindings may be created, but existing ones cannot be changed; no mutable data structures). >>>

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Steve D'Aprano
On Thu, 29 Sep 2016 03:46 am, Chris Angelico wrote: > That's exactly how a function works in an imperative language, and > it's exactly what the FP advocates detest: opaque state. So is the > difference between "function" and "monad" in Haskell the same as "pure > function" and "function" in other

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Chris Angelico
On Thu, Sep 29, 2016 at 2:43 AM, Random832 wrote: > On Wed, Sep 28, 2016, at 11:41, Paul Moore wrote: >> What "allows side effects" in languages like Haskell is the fact that the >> runtime behaviour of the language is not defined as "calculating the >> value of the main function" but rather as "m

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Chris Angelico
On Thu, Sep 29, 2016 at 2:33 AM, Steve D'Aprano wrote: Procedural programming under another name... >>> >>> Only in the sense that procedural programming is unstructured programming >>> under another name. What is a procedure call but a disguised GOSUB, and >>> what is GOSUB but a pair of GOT

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Random832
On Wed, Sep 28, 2016, at 11:41, Paul Moore wrote: > What "allows side effects" in languages like Haskell is the fact that the > runtime behaviour of the language is not defined as "calculating the > value of the main function" but rather as "making the process that the > main functon defines as an

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Steve D'Aprano
On Wed, 28 Sep 2016 11:05 pm, Jussi Piitulainen wrote: > Steve D'Aprano writes: > >> On Wed, 28 Sep 2016 08:03 pm, Lawrence D’Oliveiro wrote: >> >>> On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing >>> wrote: Essentially you write the whole program in continuation- p

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Paul Moore
On Wednesday, 28 September 2016 10:19:01 UTC+1, Chris Angelico wrote: > If monads allow mutations or side effects, they are by definition not > pure functions, and violate your bullet point. Languages like Haskell > have them not because they are an intrinsic part of functional > programming langu

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread alister
On Wed, 28 Sep 2016 21:48:20 +1000, Steve D'Aprano wrote: > On Wed, 28 Sep 2016 08:03 pm, Lawrence D’Oliveiro wrote: > >> On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing >> wrote: >>> Essentially you write the whole program in continuation- >>> passing style, with a state obj

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Jussi Piitulainen
Steve D'Aprano writes: > On Wed, 28 Sep 2016 08:03 pm, Lawrence D’Oliveiro wrote: > >> On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing >> wrote: >>> Essentially you write the whole program in continuation- >>> passing style, with a state object being passed down an >>> infinit

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Steve D'Aprano
On Wed, 28 Sep 2016 08:03 pm, Lawrence D’Oliveiro wrote: > On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing > wrote: >> Essentially you write the whole program in continuation- >> passing style, with a state object being passed down an >> infinite chain of function calls. > >

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Steven D'Aprano
On Wednesday 28 September 2016 15:27, Gregory Ewing wrote: > * No side effects (new variable bindings may be created, but >existing ones cannot be changed; no mutable data structures). As I understand it, for some advanced functional languages like Haskell, that is only true as far as the in

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Lawrence D’Oliveiro
On Wednesday, September 28, 2016 at 9:53:05 PM UTC+13, Gregory Ewing wrote: > Essentially you write the whole program in continuation- > passing style, with a state object being passed down an > infinite chain of function calls. Procedural programming under another name... -- https://mail.python.

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Chris Angelico
On Wed, Sep 28, 2016 at 6:52 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> >> wrote: >> >>> * No side effects (new variable bindings may be created, but >>> existing ones cannot be changed; no mutable data structures). >> >> >> If that's adhered to 100%, the language is useless for any

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Gregory Ewing
Chris Angelico wrote: wrote: * No side effects (new variable bindings may be created, but existing ones cannot be changed; no mutable data structures). If that's adhered to 100%, the language is useless for any operation that cannot be handled as a "result at end of calculation" function.

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: >> is Python actually a "functional language"? > > Yes [snip] No. To replace the mostly irrelevant link with something addressing my question:

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread dieter
Peng Yu writes: > Hi, In many other functional language, one can change the closure of a > function. Is it possible in python? I do not think so: the corresponding attributes/types ("__closure__", "cell") are explicitely designed to be read only. However, I never missed closure changebility. Sho

Re: Is there a way to change the closure of a python function?

2016-09-28 Thread ast
"jmp" a écrit dans le message de news:mailman.31.1474987306.2302.python-l...@python.org... On 09/27/2016 04:01 PM, Peng Yu wrote: Note: function are objects, and can have attributes, however I rarely see usage of these, there could be good reasons for that. It could be use to implemen

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Chris Angelico
On Wed, Sep 28, 2016 at 3:27 PM, Gregory Ewing wrote: > Lawrence D’Oliveiro wrote: >> >> On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: >> >>> is Python actually a "functional language"? >> >> >> Yes >>

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Gregory Ewing
Peng Yu wrote: On Tue, Sep 27, 2016 at 10:01 AM, Chris Angelico wrote: """In some languages, the variable bindings contained in a closure behave just like any other variables. Alas, in python they are read-only.""" This is not true, at least as of Python 3. So in Python 2, this is true? P

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Gregory Ewing
Lawrence D’Oliveiro wrote: On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: is Python actually a "functional language"? Yes . No, not according to what the term "functional language" usually

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Jussi Piitulainen
Chris Angelico writes: > On Wed, Sep 28, 2016 at 7:19 AM, Terry Reedy wrote: >> The value of the cell variable is writable from within the body of the >> closure function if declared nonlocal, but not otherwise, and not from >> without. The latter may be what Peng meant by 'change' and the blogge

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Peng Yu
On Tue, Sep 27, 2016 at 10:01 AM, Chris Angelico wrote: > On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: >> Hi, In many other functional language, one can change the closure of a >> function. Is it possible in python? >> >> http://ynniv.com/blog/2007/08/closures-in-python.html >> > > From the b

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Lawrence D’Oliveiro
On Wednesday, September 28, 2016 at 4:01:36 AM UTC+13, Chris Angelico wrote: > You can also have multiple closures in the same context, and changes made by > one of them will affect the others. This is the point where it’s probably easier to wrap them all together into methods of a common class.

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Lawrence D’Oliveiro
On Wednesday, September 28, 2016 at 3:35:58 AM UTC+13, Peter Otten wrote: > is Python actually a "functional language"? Yes . -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Ian Kelly
On Tue, Sep 27, 2016 at 3:19 PM, Terry Reedy wrote: > On 9/27/2016 11:01 AM, Chris Angelico wrote: >> >> On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: >>> >>> Hi, In many other functional language, one can change the closure of a >>> function. Is it possible in python? >>> >>> http://ynniv.com

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Chris Angelico
On Wed, Sep 28, 2016 at 7:19 AM, Terry Reedy wrote: > The value of the cell variable is writable from within the body of the > closure function if declared nonlocal, but not otherwise, and not from > without. The latter may be what Peng meant by 'change' and the blogger by > 'read-only'. > Not f

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Terry Reedy
On 9/27/2016 11:01 AM, Chris Angelico wrote: On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: Hi, In many other functional language, one can change the closure of a function. Is it possible in python? http://ynniv.com/blog/2007/08/closures-in-python.html From the blog post: """In some lang

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Chris Angelico
On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: > Hi, In many other functional language, one can change the closure of a > function. Is it possible in python? > > http://ynniv.com/blog/2007/08/closures-in-python.html > >From the blog post: """In some languages, the variable bindings contained i

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Ian Kelly
On Tue, Sep 27, 2016 at 8:41 AM, jmp wrote: > On 09/27/2016 04:01 PM, Peng Yu wrote: >> >> Hi, In many other functional language, one can change the closure of a >> function. Is it possible in python? >> >> http://ynniv.com/blog/2007/08/closures-in-python.html >> > > If I understood correctly your

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread jmp
On 09/27/2016 04:01 PM, Peng Yu wrote: Hi, In many other functional language, one can change the closure of a function. Is it possible in python? http://ynniv.com/blog/2007/08/closures-in-python.html If I understood correctly your link: (untested) def func(x): return x+func.y func.y = 1

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Peter Otten
Peng Yu wrote: > Hi, In many other functional language, one can change the closure of a > function. Which are those languages, and how do they work? And is Python actually a "functional language"? > Is it possible in python? I'm not sure what you mean. Something like >>> def f(x): ... d

Is there a way to change the closure of a python function?

2016-09-27 Thread Peng Yu
Hi, In many other functional language, one can change the closure of a function. Is it possible in python? http://ynniv.com/blog/2007/08/closures-in-python.html -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list