logoalt Hacker News

ndriscolltoday at 12:12 AM1 replyview on HN

  def reduce(acc, f): 
    for v in self:
      acc = f(acc, v)
    return acc
The current acc goes out of scope each time you call f. There's no shared reference (assuming f doesn't sneak store it elsewhere, which for string combining, f should just be `return a+b`?).

Replies

edflsafoiewqtoday at 1:39 AM

The binding for acc in the reduce call is still active during the f call, which means there are at least two references to acc.

show 1 reply