I've used the following method in other programming languages (Lua, Janet)
and I'm wondering whether I can do something similar in PicoLisp:

I've got a coroutine that generates an infinite sequence of data.

I've got another coroutine that takes data from the previous coroutine,
processes it and generates a sequence (also infinite) of modified data. The
original coroutine is kept in its parent coroutine's local variable.

Another coroutine takes this modified data, modifies it further and
generates another sequence.

This happens on several levels, around 5 - 10 coroutines chained like this,
each of them generating an infinite sequence of data based on its "child"
coroutine (kept in local variable) data and passing the modified sequence
to its "parent" using "yield".

Finally the top level parent does something with this generated data and,
after some time stops and forgets the reference to it direct "child"
coroutine.

At this time, the direct child coroutine is automatically garbage
collected. This releases the reference to next level "child" coroutine,
this is also garbage collected etc., etc. until the original coroutine that
was generating the first sequence.

The upshot of this method is that I don't have to manually kill any of the
coroutines, they are all automatically garbage collected when I no longer
use them.

If I understand it correctly, creating a coroutine in PicoLisp creates a
global symbol that keeps the reference to this coroutine so I have to
explicitly remove the coroutine when I no longer need it - it can never get
automatically garbage collected because it's linked to a global symbol.

Is there a similar mechanism in PicoLisp? Keeping the coroutine reference
in the local scope so that it's automatically destroyed when it goes out of
scope?

P.S: It seems that I have problem receiving any email from this mailing
list so I'll probably have to post follow ups to this topic in the IRC
channel after I read the replies in the mailing list web archive...
----------------------
-- František Fuka

Reply via email to