Re: Weird lambda rebinding/reassignment without me doing it

2008-07-12 Thread Steven D'Aprano
On Sat, 12 Jul 2008 16:32:25 -0400, Terry Reedy wrote: > Steven D'Aprano wrote: >> On Thu, 10 Jul 2008 14:09:16 -0400, Terry Reedy wrote: >> g = lambda x:validate(x) >>> This is doubly diseased. >>> >>> First, never write a 'name = lambda...' statement since it is >>> equivalent to a def

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-12 Thread Terry Reedy
Steven D'Aprano wrote: On Thu, 10 Jul 2008 14:09:16 -0400, Terry Reedy wrote: g = lambda x:validate(x) This is doubly diseased. First, never write a 'name = lambda...' statement since it is equivalent to a def statement except that the resulting function object lacks a proper .funcname attr

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-12 Thread Steven D'Aprano
On Thu, 10 Jul 2008 14:09:16 -0400, Terry Reedy wrote: >> g = lambda x:validate(x) > > This is doubly diseased. > > First, never write a 'name = lambda...' statement since it is equivalent > to a def statement except that the resulting function object lacks a > proper .funcname attribute. U

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-11 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, ssecorp <[EMAIL PROTECTED]> wrote: > >>> def mod(x,y): > return x.append(y) > > >>> mod([1,2],3) > >>> k=[1,2,3] > >>> k > [1, 2, 3] > >>> l = mod(k,4) > >>> l > >>> k > [1, 2, 3, 4] > >>> l > >>> k==l > False > >>> mod(k,5) > >>> k > [1, 2, 3, 4, 5] > >>>

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-11 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, Terry Reedy <[EMAIL PROTECTED]> wrote: > David C. Ullrich wrote: > > In article > > <[EMAIL PROTECTED]>, > > ssecorp <[EMAIL PROTECTED]> wrote: > > > >> I am never redefining the or reassigning the list when using validate > >> but since it spits the modified li

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-10 Thread MRAB
On Jul 10, 9:46 pm, ssecorp <[EMAIL PROTECTED]> wrote: > >>> def mod(x,y): > >         return x.append(y) > append adds y to list x and returns None, which is then returned by mod. > > > >>> mod([1,2],3) > >>> k=[1,2,3] > >>> k > [1, 2, 3] > >>> l = mod(k,4) 4 has been appended to list k and mod h

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-10 Thread ssecorp
>>> def mod(x,y): return x.append(y) >>> mod([1,2],3) >>> k=[1,2,3] >>> k [1, 2, 3] >>> l = mod(k,4) >>> l >>> k [1, 2, 3, 4] >>> l >>> k==l False >>> mod(k,5) >>> k [1, 2, 3, 4, 5] >>> mod(l,4) Traceback (most recent call last): File "", line 1, in mod(l,4) File "", line 2, in m

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-10 Thread ssecorp
ty very good answer. i know i shouldn't use lambda like that, i never do i was just playing around there and then this happened which i thought was weird. On Jul 10, 8:09 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > David C. Ullrich wrote: > > In article > > <[EMAIL PROTECTED]>, > >  ssecorp

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-10 Thread Terry Reedy
David C. Ullrich wrote: In article <[EMAIL PROTECTED]>, ssecorp <[EMAIL PROTECTED]> wrote: I am never redefining the or reassigning the list when using validate but since it spits the modified list back out that somehow means that the modified list is part of the environment and not the old

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-10 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, ssecorp <[EMAIL PROTECTED]> wrote: > I am never redefining the or reassigning the list when using validate > but since it spits the modified list back out that somehow means that > the modified list is part of the environment and not the old one. > i thought what

Re: Weird lambda rebinding/reassignment without me doing it

2008-07-10 Thread A.T.Hofkamp
Python doesn't use value semantics for variables but reference semantics: a = [1] b = a In many languages, you'd now have 2 lists. In Python you still have one list, and both a and b refer to it. Now if you modify the data (the list), both variables will change a.append(2) # in-place modificat