Skip to main content

cs_921

Box and pointer ntoation in Environment Diagrams Lists are represented as a row of index-labeled adjacent boxes, one per element. Each box either contains a primitive value or points to a compound value

Global frame:

  • pair -> List containing 1 and 2
  • nested_list -> List containing [1,2], [], and [[3,False,None],[something else]]

Snippet of code:

f = [3]
a = [1,f]
b = [f,2]

f = 'dog'
#so we have:
x = 3
f = [x]
a = [1,f]
b = [f,2]

f = 'dog'
x = 2

We see that f does not change, since x is a number it obviously is not a pointer. f is initialised with the value of x,, rather than the pointer to the number 3.

We have SLICING

Another code snippet:

odds = [3,5,7,9,11]
[odds[1],odds[2]]
= [5,7]
range(1,3)
list(range(1,3)) = [1,2]

odds[1:3] = #slice of odds

odds= [3,5,7,9,11]
sum(odds) = 35
sum(odds,start=100) = 135 -> basically start counnting from 100
range(10) #This is basically ranging from 0 to 9

sum(lol, start = [])