I'm fascinated to see Steve Losh demonstrating a 'gather' macro in Common Lisp, removing boilerplate for an accumulator: https://stevelosh.com/blog/2018/05/fun-with-macros-gathering/
Most use of yield in Python seems to be focused on gathering rather than lazy evaluation, but I never had a name for the concept!
miniblog.
Related Posts
@cstanhope Interesting, I didn't know that about Pascal!
Go does make returning an accumulator a little more concise. Compare with e.g. Python:
def foo():
res = [] # not needed in Go
for x in y:
if z:
res.append(x)
return res
That's the biggest advantage I can see though.