jamiebuilds / ghost-lang

:ghost: A friendly little language for you and me.
302 stars 10 forks source link

🚲Why `effect` instead of `yield`? #5

Closed aleclarson closed 6 years ago

aleclarson commented 6 years ago

And should the function be marked as effectful (eg: *fn () {})?

Any function that throws would need the asterisk, IMO.

edit: And maybe use co instead of *fn?

aleclarson commented 6 years ago

Just saw that yield is used for iterables. Maybe for-as can "just work" with any coroutine, not just iterables?

aleclarson commented 6 years ago

Also, maybe make it so generators (eg: *fn/co functions) are async by default. Since whether or not a generator is async is really an implementation detail, right?

jamiebuilds commented 6 years ago

effect's behavior is somewhere in between throw and yield, all three are valid programming patterns

aleclarson commented 6 years ago

Can a function use all four (effect, throw, yield, await) or are there restrictions?

jamiebuilds commented 6 years ago

Assuming it's a fn () async iter {...}, then yes it can use all four

aleclarson commented 6 years ago

What can I do with effect that I can't do with throw?

jamiebuilds commented 6 years ago

You can resume it from a catch {} handler with a value