I implemented this iter.Pull strategy for keeping parser state, instead of
using a background goroutine (as I did for years) in my pure Go lisp, zygomys,
and the resulting code is much easier to read and follow, and about 12% faster on
Linux (although 0.3% slower on Darwin).
Details and specific code here:
v8.1.0 has the old goroutine version, v9.0.7 has the new iterator pull (implicit coroutine, so
no linkname hacking required) version, if you want to compare code side-by-side.
See the zygo/parser.go file specifically to compare the read-ability.
It might look a little strange, because you store the iterator, the yield(), next(), and stop() func
as members in the Parser state, but it works, and works well.
I'm much happier re-using my library for things like JSON or config parsing without having to worry about
the extra background goroutine in my stack dumps, which was always a bit surprising.
- Jason