

def ticker(p):
  p.n += 3



def mkTick(n):
  count = [n] 
  def next():
    count[0] += 1
    return count[0]
  return next

def mkTick2(n):
  count = n 
  def next():
    return count[0]
  return next

baz = mkTick2("cat")
z0  = baz()
z1  = baz()
z2  = baz()




foo = mkTick(5)
x0  = foo()
x1  = foo()
x2  = foo()

bar = mkTick(1000)
y0  = bar()
y1  = bar()
y2  = bar()

def mkTick3(n):
  def next():
    return count[0]
  return next

goo = mkTick3("cat") 















#imperative
i,s = 0,0
while (i <= 3):
    i,s = i+1, s+i
    print i
    print s



#aliasing
x = [0]

y = x

y[0] = "a"

x



#namespaces

__builtins__

__builtins__.__dict__.keys()

#creating namespaces: modules

import a

import b

a

b

a.__dict__.keys()


b.__dict__.keys()


(a.x, a.y)

(b.x, b.y)


a.x = ["sirius","black"]

b.y = a.x 

b.y[0] = ["remulus"] #aliasing


globals()

x = 102

globals()




# creating local namespaces 
x = 10
def f(y):
  y = y + x
  return y

f(x)

#202 368 9092







y = 0
x = [10]

def f(y):
  z = len(x) + y
  return z


f(5)












def g(y): return y + n

g(5)







n = 10
g(5)















n = 100

g(5)



















n

def f():
  n = "smash"
  print n

f()

n








x = 10

def f():
  x = x + 1
  print x

f()












x = 10

def f(y):
  y = y + x
  return y

f(x)

x






x = [10]

def f(y):
    x[0] = y

f("hogwart")

x











x = [10]

def f(y):
  def h(z): return (y+x[0]+z)
  return h

foo = f(5)

foo

foo(100)

foo1 = f(-5)

foo1

foo1(100)

x = [100]

foo(100)

foo1(100)
















x = [0]

def f(y):
  def g():
    x[0] = x[0] + 1
    y[0] = y[0] + 1
    return (y[0],x[0])
  return g

foo1 = f([100])

foo2 = f([1000])

[foo1(),foo1(),foo1(),foo1(),foo2(),foo2(),foo2(),foo2()]

















