5 ms·
> Now let's see an example with toss. This is used mostly for passing multiple values out of the function. You don't really need it, but it's cute. Not useful?
by kibwen 2y ago
> Now let's see an example with toss. This is used mostly for passing multiple values out of the function. You don't really need it, but it's cute.
Not useful? You've implemented resumable generators! Of course, getting them to do anything except resume immediately might be... exciting. :P Just need to structure your entire codebase as an inside-out stack of `toss`es...
- adastra22 2y agoYeah that made me chuckle. I wish the languages I use had resumable exception handling. This is a ridiculously good, and extremely useful feature. Great for API callbacks, among other things.
- grumpyprole 2y agoOCaml 5 essentially has it, as "effect handlers". It's how lightweight concurrency is implementated.
- 1propionyl 2y agoExactly my first thought after reading that. Part of me wonders if it's a bit of a joke, panning a genuinely useful feature (in any other language) as disposable and silly (in this one).
- DeathArrow 2y ago>You've implemented resumable generators! Like yield in C#?
- kleiba 2y agoRight. Lots of fun ahead debugging a larger codebase :-)
- int_19h 2y agoNot quite, since with resumable generators you can resume at any later point in the program, while here "return" must be lexically scoped to the handler (whereas in e.g. Python you can call next() wherever). This is really more like passing a callback through a side channel. "toss" is invoking said callback, and "return" is, well, returning from it.
- boromisp 2y agoIt's more like stack based event propagation.
- Vivtek 2y agoThat was my first thought, too. Nice, tiny language with generators? Neat!