Loops/Increment loop index within loop body: Difference between revisions

Content added Content deleted
m (→‎Functional Python: Updated output.)
Line 3,259: Line 3,259:
def go(tpl):
def go(tpl):
if isPrime(tpl[1]):
if isPrime(tpl[1]):
# Side effect.
print(showTuple(tpl))
print(showTuple(tpl))
# Value.
return splitArrow(succ)(dbl)(tpl)
return splitArrow(succ)(dbl)(tpl)
else:
else:
Line 3,285: Line 3,287:


return not any(map(p, range(5, 1 + int(n ** 0.5), 6)))
return not any(map(p, range(5, 1 + int(n ** 0.5), 6)))


# showTuple :: (Int, Int) -> String
def showTuple(tpl):
'''Second integer shown with comma-chunked digits.'''
return '{:2} -> {:20,}'.format(*tpl)




Line 3,336: Line 3,344:
yield v
yield v
v = f(v)
v = f(v)
return lambda x: go(x)
return go




Line 3,345: Line 3,353:
'''
'''
return lambda tpl: (tpl[0], f(tpl[1]))
return lambda tpl: (tpl[0], f(tpl[1]))


# showTuple :: (Int, Int) -> String
def showTuple(tpl):
'''Integer string with comma-chunked digits.'''
return '{:2} -> {:20,}'.format(*tpl)