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.

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