Thanks for elaborating the point. Maybe it’s better to tweak the manual and recommend
open(filename) do io
for line in eachline(io)
...
end
end
? Doing this is probably not super important for throw-away scripts but it is if you open a lot of files, implement long-running services, etc.
Re: CPS I just found
I guess it’s possible to define iterate
/foldl
from a single “function” definition syntax (something like Python’s yield
, syntax-wise) by somehow hooking into this. Defining both iterate
and foldl
at the same time would be nice so that the “iterator” created by this syntax would work outside of the foldl
API. It should also be possible to automate something like Tail-call optimization and function-barrier -based accumulation in loops