3 ms·
Inspired by Lisp's condition system I wrote a ruby library which comes pretty close to Lisp's error handling. It also implements "restarts" ... a little bit mes
by andregawron 15y ago
Inspired by Lisp's condition system I wrote a ruby library which comes pretty close to Lisp's error handling. It also implements "restarts" ... a little bit messy though since, as you said, low-level execption are used to get it working. In one point the condition system bootstraps itself which is quite interesting to think about.
https://github.com/melkon/conditions https://github.com/melkon/conditions
An example ("parse_log_file" and "log_analyzer show restarts"):
https://github.com/melkon/conditions/blob/master/example/example.rb https://github.com/melkon/conditions/blob/master/example/exa...
In the beginning I thought it can only be ported to Ruby because I used some Ruby-specific features. The exception solution (which I implemented later) should work in a lot of different languages though.
Another thing is, if you understood the condition system, you can use it for a lot of different things besides error handling. You can build protocols on top of that, event handling etc. Freedom is yours.
- vito 15y agoHave you considered using Ruby's throw/catch instead of exceptions? I did that for Atomy's condition system[1]. They worked great because you can just use the restart names for the throw/catch tags. [1]: https://github.com/vito/atomy/blob/master/kernel/condition.ay https://github.com/vito/atomy/blob/master/kernel/condition.a...
- andregawron 15y agoI might have considered throw and catch as I wrote the library, but right now, I cannot think of any good reason why I haven't used it. Will check that again. Thanks for the suggestion.