Implementing Co, a Small Interpreted Language With Coroutines #1: The Parser

4 Likes

A very interesting post. Thank you!

I have one question and one comment:

Question: I don’t understand how the ping pong example works. You mention that using coroutines a process needs to yield the ToC, but I don’t see any yielding in the program. What’s going on?

Comment: I think this use of try will make some of the reported errors cryptic and inaccurate. Because if for example if there is a parse error in the third argument in a function call, the entire function call expression is given up on and instead the parser will try the identifier route.

Instead, you want to do left factoring: parse the common prefixes together and then choose between the function call route (which starts with parens) and simply returning the identifier. try a <|> b considered harmful talks about this topic in length.

1 Like

Thanks a lot for the kind words :slight_smile:. I learned a lot about this topic from your Streama screencasts.

This is the first part of a three-part series. I’ll go over how coroutines and channels work in the third part. But in short, sending and receiving over channels implicitly yields.

I agree. I wrote it this way to keep things simple. I didn’t want to add extra mental overhead for the readers.

1 Like

I see! I’ll keep an eye for the next posts :slight_smile:

Keeping it simple is good. I would suggest mentioning the article above just in case someone runs into issues.

I think concurrency in PLT is very interesting and important and there aren’t a lot of non academic articles about this topic, so it’s great that you are writing about it! The article and examples are pretty clear to me overall. Good job!

And I’m glad to hear my streams were helpful :slight_smile: