Here is an *attempt* to simulate generators of the Python language using Arnesi CPS transformer.
The macro defgenerator allow to define new generators. A 'yield' function is implictly available in the body of the generator.
In the Python language, the generators looks like functions and use the 'yield' keyword to return value to the caller. But unlike when returning with the 'return' keyword, the function call can continue by iterating the generator. This construction is very convenient to build various iterators over structures.
It's the first time I use CPS. It works, but I don't know why, because all of the CPS thing is pure magic to me. I don't know if this is really a good way to use it for such purpose. Any comments welcome.
Tested with SBCL 0.9.12, and Arnesi 1.4.0, on Linux x86-32.
Some examples using the code below:
(defgenerator some-numbers () (loop for i from 1 upto 3 do (yield i)) (print 'some-message) (loop for i from 8 upto 9 do (yield i)))