nim-works / cps

Continuation-Passing Style for Nim 🔗

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request for review of tutorial

zevv opened this issue · comments

I created a crude tutorial to get started with CPS:

https://github.com/zevv/cpstut

If you find the time please go through it and tell me what's wrong or missing.

Just went through it. Typo fixes etc. are over as a PR in the repo. Now for some notes about my understanding.

First of all now I actually understand how this stuff is used. Thanks for that!

Regarding whelp

Why is it required? It isn't clear to me why the cps macro
couldn't just rewrite the body and return value such that whelp X is
returned? Is that what is meant by "for technical reasons"?

Regarding state "running" of a continuation

It would be good to explain better what is meant by being in a
state "running". Does it simply mean the last run trampoline isn't the "last" one?
As in the continuation is currently ready to run its next leg?

This is at least what I understand from the next part.

And there is one "leg" that's just "starting" the continuation right?
Otherwise the first example would have finished immediately (it was
running, but didn't finish until we called the fn once).

Regarding runWork impl

The code reads as if the first element popped from the queue would be
completely finished immediately, as we only leave the while loop, once
the state isn't running anymore. It's not entirely clear how this
makes each continuation only run one leg to me.
Or is it simply because in the lower example we use the schedule
function, which explicitly returns nil to terminate the trampoline?

Finally

You're our ASCII art master.

Thanks for the through reviewing vindaar, I'll see how can I can incorporate your comments in the doc!