Re: Python's Reference And Internal Model Of Computing Languages
I read thisand am a tiny bit confused about the actual problem. It's not exactly complex to realize that something like: a = b = array that a and b both point to the array. Logically speaking, I'm not sure how one could assume that the same assignment would yield a and b point to the same duplicate array. If that was the case, why not do: a = array.. b = array.. I know with what you were complaining about a few days ago, .clear makes perfect sense. If a and b point to the same array, clear should clear both arrays. Again, if you didn't want that to happen, create a duplicate array. Personally I feel that this complexity doesn't hamper programming process, and yes while its good for efficiency it also just makes sense. Also, I wouldn't look at PHP on the right way to do something programming wise. I have ~5 years experience in this language, and I dislike it a whole lot. There's a lot of things it should do right that it doesn't out of convenience. -David www.thedarktrumpet.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Reference And Internal Model Of Computing Languages
David Thole dth...@gmail.com wrote in comp.lang.perl.misc: I read thisand am a tiny bit confused about the actual problem. It's not exactly complex to realize that something like: a = b = array that a and b both point to the array. ??? What are you talking about? First of all you should post actual code, not pseudo-code because pseudo-code leads to misunderstandings. Did you mean @a = @b = @array Second what do you mean by pointing? That is a very ambiguous term. if you do the assignment as written above then @a and @b will be _copies_ of @array. If you want two additional references to the same array insted then you have to create that reference first and assign that reference to $a and $b instead of copying the array, see perldoc perlref for details. And remember, references are scalars, no matter if they reference other scalars or arrays. Logically speaking, I'm not sure how one could assume that the same assignment would yield a and b point to the same duplicate array. If Now what? The same array or a duplicate array? Two very different and mutually exclusive things. that was the case, why not do: a = array.. b = array.. Which, after correcting the obvious syntax errors is the same as the code above. I know with what you were complaining about a few days ago, .clear makes perfect sense. If a and b point to the same array, clear should clear They don't point, they are copies. And what do you mean by clear? both arrays. Again, if you didn't want that to happen, create a duplicate array. But that is what that code above does. If you want references then create references. jue -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Reference And Internal Model Of Computing Languages
[Followup-To: header set to comp.lang.perl.misc.] Jürgen Exner jurge...@hotmail.com wrote: David Thole dth...@gmail.com wrote in comp.lang.perl.misc: I read thisand am a tiny bit confused about the actual problem. It's not exactly complex to realize that something like: a = b = array that a and b both point to the array. ??? What are you talking about? First of all you should post actual code, First of all, we should not be feeding the troll! actual code in one of Perl, Python or Lisp? -- Tad McClellan email: perl -le print scalar reverse qq/moc.liamg\100cm.j.dat/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Reference And Internal Model Of Computing Languages
On Fri, 05 Feb 2010 09:53:33 -0600, David Thole wrote: I read thisand am a tiny bit confused about the actual problem. It's not exactly complex to realize that something like: a = b = array that a and b both point to the array. Logically speaking, I'm not sure how one could assume that the same assignment would yield a and b point to the same duplicate array. It's an easy mistake to make, if you don't understand Python's object model: a = b = 2 a += 1 a, b (3, 2) a = b = [2] a[0] += 1 a, b ([3], [3]) For the non-Python coders reading, the difference is that ints are immutable, and hence a += 1 assigns a to a new int, leaving b untouched, but lists are mutable, hence a[0] += 1 mutates the list which both a and b refer to. This is a Good Thing, but it is one of the things which give newcomers some trouble. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Reference And Internal Model Of Computing Languages
On Tue, 2010-02-02 at 17:28 -0800, Xah Lee wrote: I know, I know, do not feed the trolls. But this is just so *wrong* that I can't help myself. In Python, there are 2 ways to clear a hash: No, no there's not. There's one way to clear a hash and there's one way to assign a new object to a variable. “myHash = {}” and “myHash.clear()”. What is the difference? The difference is that “myHash={}” simply creates a new empty hash and assigns to myHash, while “myHash.clear()” actually clear the hash the myHash is pointing to. What does that mean?? Here's a code that illustrates: # python # 2 ways to clear hash and their difference aa = {'a':3, 'b':4} bb = aa aa = {} print bb # prints {'a': 3, 'b': 4} aa = {'a':3, 'b':4} bb = aa aa.clear() print bb # prints {} This is like this because of the “reference” concept. ...snip inane babble... Languages that do not have any “reference” or “object”, or otherwise does not require the programer to have some internal model of source code, are: Mathematica, JavaScript, PHP. (others may include TCL, possibly assembly langs.) Just so we're all clear exactly how much thought has gone into this little rant, here's a transcript from a JavaScript session: var aa = {}; var bb = aa; aa.hello = world; alert(bb.hello) -- world delete bb.hello alert(aa.hello) -- undefined OMFG, references!! Come to think of it, the JavaScript and Python object models are really very similar. I'm genuinely curious now - what little sprinkle of magic fairy dust has earned JavaScript objects the Xah Lee seal of approval while Python objects miss out? Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Reference And Internal Model Of Computing Languages
Ryan Kelly r...@rfk.id.au writes: I know, I know, do not feed the trolls. But this is just so *wrong* that I can't help myself. See: http://xkcd.com/386/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Reference And Internal Model Of Computing Languages
()On Feb 2, 6:46 pm, Ryan Kelly r...@rfk.id.au wrote: On Tue, 2010-02-02 at 17:28 -0800, Xah Lee wrote: I know, I know, do not feed the trolls. But this is just so *wrong* that I can't help myself. In Python, there are 2 ways to clear a hash: No, no there's not. There's one way to clear a hash and there's one way to assign a new object to a variable. “myHash = {}” and “myHash.clear()”. What is the difference? The difference is that “myHash={}” simply creates a new empty hash and assigns to myHash, while “myHash.clear()” actually clear the hash the myHash is pointing to. What does that mean?? Here's a code that illustrates: # python # 2 ways to clear hash and their difference aa = {'a':3, 'b':4} bb = aa aa = {} print bb # prints {'a': 3, 'b': 4} aa = {'a':3, 'b':4} bb = aa aa.clear() print bb # prints {} This is like this because of the “reference” concept. ...snip inane babble... Languages that do not have any “reference” or “object”, or otherwise does not require the programer to have some internal model of source code, are: Mathematica, JavaScript, PHP. (others may include TCL, possibly assembly langs.) Just so we're all clear exactly how much thought has gone into this little rant, here's a transcript from a JavaScript session: var aa = {}; var bb = aa; aa.hello = world; alert(bb.hello) -- world delete bb.hello alert(aa.hello) -- undefined OMFG, references!! Come to think of it, the JavaScript and Python object models are really very similar. I'm genuinely curious now - what little sprinkle of magic fairy dust has earned JavaScript objects the Xah Lee seal of approval while Python objects miss out? Thanks. You are right. I think i put JavaScript there without much thinking. Xah -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Reference And Internal Model Of Computing Languages
Paul Rubin wrote: Ryan Kelly r...@rfk.id.au writes: I know, I know, do not feed the trolls. But this is just so *wrong* that I can't help myself. See: http://xkcd.com/386/ :-) -- http://mail.python.org/mailman/listinfo/python-list