Jensen's Device: Difference between revisions
Content added Content deleted
(added c) |
|||
Line 171: | Line 171: | ||
i = Ref() |
i = Ref() |
||
def sum( |
def sum(i, lo, hi, term): |
||
# term is passed by-name, and so is i |
# term is passed by-name, and so is i |
||
temp = 0 |
temp = 0 |
||
i.value = lo |
|||
while i.value <= hi: # Python has a for loop but it creates a distinct |
|||
⚫ | |||
temp += term() |
temp += term() # variable which would not be shared with the passed i |
||
⚫ | |||
return temp |
return temp |
||
# note the correspondence between the mathematical notation and the call to sum |
# note the correspondence between the mathematical notation and the call to sum |