1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
# The following lets a property escape from local context without
# being kept on the cadabra stack. This is undefined.
def fun():
{A,B,C}::AntiCommuting.
ex:= C B A
sort_product(_)
print("inside fun")
print(_)
return __cdbtmp__
prop=fun()
print(prop)
ex:= C B A
sort_product(_)
# Mixing properties from global and local scope.
{A,B,C}::AntiCommuting.
qg = 42
def fun3():
print('=== locals in fun3 scope ===')
# print(q) # this would not work
print(qg)
{K,L}::AntiCommuting.
ex:= C B A
sort_product(_)
print(_)
# This function does not see things declared in fun2,
# and it should not, because it does not see 'q' above either.
ex2:= F E D
sort_product(_)
print(_)
print(locals())
# FIXME: in this problem, even though three local kernels get created,
# only two of them show up: in fun3 & fun4 the kernel is the same.
def fun2():
q=3
{D,E,F}::AntiCommuting.
print("fun2 scope "+str(properties()))
ex:= C B A
sort_product(_)
print(_)
ex2:= F E D
sort_product(_)
print(_)
fun3()
__cdbkernel__ = Kernel()
print(__cdbkernel__)
def fun4():
print('=== locals in fun4 scope ===')
print("fun4 scope "+str(properties()))
print(locals());
print q
# If you drop this print below, __cdbkernel__ will not be in locals above.
#print __cdbkernel__
{Q,R}::AntiCommuting.
ex4:= R Q
sort_product(_)
print(_)
# This does not see the fun2 scope (but it does of course see
# the global scope). That's wrong...
ex5:= D E F
sort_product(_)
print(_)
fun4()
print("fun2 scope "+str(properties()))
ex3:= R Q
sort_product(_)
print(_)
print('=== locals in fun2 scope ===')
print(locals())
# print('=== globals ===')
# print(globals())
fun2()
ex3:= F E D
sort_product(_)
print(_)
|