The key to making a compound object is to put the individual objects into a list, then give that list to the compound function:
boxes = []
for i in range(40):
b=i/8
boxes.append( box(width=10-b,length=6, height=1, pos=vec(0,i+1-30,b/2)) )
building = compound(boxes)
Note that you don't need to create a variable a that starts at 1; the quantity i+1 is the same as your a.
Bruce