Movatterモバイル変換
[0]ホーム
Changing global variables in tkinter/pmw callback
Marcin 'Qrczak' Kowalczykqrczak at knm.org.pl
Tue Apr 10 17:51:51 EDT 2001
Fri, 6 Apr 2001 10:45:00 +0200, Alex Martelli <aleaxit at yahoo.com> pisze:> If some place after the call you had for example a loop such as> DO 10, I=1,3> then the loop's body would 'of course' now be executed four times,> for example.>> We _don't_ really want this, do we? Numbers *had better* be> completely immutable objects -- programming becomes a funny> game indeed if the actual values of numbers start changing> from under our feet.I would say that if numbers were immutable, then using a numericliteral would have to allocate a fresh object each time, otherwisethe semantics would be too confusing, if well defined at all.Immutability allows unrestricted sharing of values which lookthe same. For immutable objects generally only '==' matters, not'is'. Deep copying becomes equivalent to all kinds of shallow copyingand to rebinding a reference. Passing by value becomes equivalent topassing by reference.In an immutable world the 'boxes' and 'post-it tags' paradigms areunified - to the point that some people are confused and believethat Python works according to the 'boxes' paradigm, until they leavethe immutable world and want to observe mutation of an integer. Theycan't create a reference to a mutating integer, because it was notthe integer which was mutating, only the object which contained it...When a language with 'post-it tags' semantics wants to expressboxes with changing contents, it can do it in two styles: eitherintroduce a boxing mechanism for individual objects (this is whatSML and Haskell do), or pack multiple objects into some structureswith mutable contents (this is what Python and OCaml do). Either ofthese styles can simulate the other one.-- __("< Marcin Kowalczyk *qrczak at knm.org.plhttp://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTĘPCZAQRCZAK
More information about the Python-listmailing list
[8]ページ先頭