Python Scope Complexity, Shallow Copy, Deep Copy, Circular List, and the Garbage Underneath Computer Languages

By Xah Lee. Date: . Last updated: .

been stung by this again.

# -*- coding: utf-8 -*-
# python

# a global array
aa = [0,1,2]

def f ():
    aa[0]  = 88   # this is ok. global array will be updated

def g ():
    aa  = []     # WRONG! global array will NOT be updated

f()

print aa                        # prints [88, 1, 2]

g()

print aa                        # prints [88, 1, 2]

the tech excuse has to do with how Python looks up variables. i.e. Python's variable scope.

i really hate all these language with references or whatnot garbage underneath. Same complex thing happens when you copy list (thus you beget “deep copy”, “shallow copy”, “circular list”, dung like that). Of course, the fanatics of each language will start to mumble about technicalities particular to each of their own, and accuse you no-unstand. YOU NO UNSTAND!

in general, functional programing language don't have these dung, especially Mathematica. Everything is just a copy. Old lispers, in particular the Common Lispers, also no unstand. Froth form over their mouths, and speakths of lisp's “object”, “internal representation”, “lisp reader”, habla mumbla et alia.

see some past spats.

Python Semantic Bad

  1. Why List Comprehension is Bad
  2. Python 3: Map with Side Effect Doesn't Work If Result is Not Used
  3. The Idiocy of Python's Function Parameter Specification
  4. Python Scope Complexity, Shallow Copy, Deep Copy, Circular List, and the Garbage Underneath Computer Languages
  5. Python: What's the Difference Between 「dict={}」 vs 「dict.clear()」?
  6. Python: Get Number of Arguments of Function
  7. Python: Copy Nested List, Shallow/Deep Copy
  8. Python: Keyword Argument Default Value Unstable
  9. Python: Append String in Loop
  10. FCK Python: String Methods, Functions, Slashes and Backslashes
  11. Python Bitwise Invert Oddity
  12. From Why Not Ruby to FCK Python, Hello Ruby
  13. Why Learn Lisp When There Are Perl and Python

If you have a question, put $5 at patreon and message me.