[ANN] ribol "v0.2.1" - comprehensive document on conditional restart systems

299 views
Skip to first unread message

zcaudate

unread,
Sep 25, 2013, 3:14:09 AM9/25/13
to clo...@googlegroups.com
I've done a pretty comprehensive guide on conditional restart systems in clojure with diagrams to show why it is much more flexible over try/catch mechanism

Project:

Generated Documentation:



Baishampayan Ghose

unread,
Sep 25, 2013, 5:58:30 AM9/25/13
to Clojure Group
This is brilliant, thanks! ~BG
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Baishampayan Ghose
b.ghose at gmail.com

Dima Sabanin

unread,
Sep 25, 2013, 11:26:37 AM9/25/13
to clo...@googlegroups.com
Hi Chris!

Great library! I'm trying to apply this to a project I'm working on, but I'm somewhat new to the conditional restarts theory. What would I use instead of Clojure's finally block to properly free up the resources on error escalation?

-- 
Thanks,
Dima Sabanin
http://twitter.com/dimasabanin


--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Best regards,
Dima Sabanin
http://twitter.com/dimasabanin

zcaudate

unread,
Sep 25, 2013, 7:18:48 PM9/25/13
to clo...@googlegroups.com
Hi Dima,

That's actually a really good question. I don't think it possible currently :)

I think I do need to support a finally clause.... But can you give a code example of how you might want to write such a thing?

Dima Sabanin

unread,
Sep 25, 2013, 10:18:58 PM9/25/13
to clo...@googlegroups.com
Something as simple as (finally) block in (manage) would work for me, but I'm not sure how it fits the philosophy. As I said, I've read about conditional restarts in Common Lisp, but never actually used it in the real project. I wonder how finally block is implemented there?


--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

zcaudate

unread,
Sep 25, 2013, 10:20:47 PM9/25/13
to clo...@googlegroups.com
Hi Dima,

You can now put 'finally' clause in v0.2.2, just loaded onto clojars. 

I haven't done an example on the readme yet....

but the following should print a hello and return [1 2 :A]:

(manage                          ;; L2
 [1 2 (manage                    ;; L1
       (raise :A)                ;; L0
       (on :A [] :A))]           ;; H1A
 (on :B [] :B) (finally (print "hello")))
Chris.

Dima Sabanin

unread,
Sep 26, 2013, 2:32:48 PM9/26/13
to clo...@googlegroups.com
Thanks for implementing this!

I found myself in a situation when I needed to provide different exceptions types triggering different errors in the raise-on macro. I implemented this as a macro that's just nesting the raise-on blocks: https://gist.github.com/dsabanin/6717877

Is that something that makes sense? If it is, it probably makes sense to extend raise-on macro with this, but it might get a bit complex after that.

Chris Zheng

unread,
Sep 26, 2013, 4:22:29 PM9/26/13
to clo...@googlegroups.com
Hi Dima,

I think you can already add multiple types of exceptions with raise-on... I am sure it was there in my tests... :) will confirm today. It shouldn't be too hard to add a finally clause into the raise-on macro... Thanks for you suggestion

i would caution again using too much of raise-on.... in the example that you gave, raise-on acts like a catch. The stack is lost right up at that point. And so you won't get any benefits on being able to call 'continue' by using it like that to deal with different types of circumstances.
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/elRWA13Iidg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

Lee Spector

unread,
Sep 26, 2013, 9:06:48 PM9/26/13
to clo...@googlegroups.com

I apologize for the naivety of this question, but whenever I see libraries/discussions of enhanced mechanisms for exceptions/conditions/errors/restarts/etc in Clojure I wonder if they could provide a couple of features that I dearly miss from Common Lisp, and this contribution makes me wonder the same thing. I looked briefly through the guide (nice diagrams!) but couldn't quite tell if it could do what I miss from Common Lisp in Clojure, and therefore whether I should take the time to study it in more detail.

What do I miss from Common Lisp condition handling?

When you hit an error in Common Lisp you get a REPL (sometimes called a "break loop") that lives in the context where the error occurred. The most useful thing to me is that you can examine the state of the system there (through normal REPL interactions) and look at the values of local variables all up and down the stack. In addition, you can change the values of variables and restart the computation, and the restart mechanisms can be customized based on the type of error/condition... which is very cool and occasionally useful, but for me personally the big win is in just being able to really examine the state at the point of the error (including running little pieces of code to help to examine the state, etc.).

Note that this happens in Common Lisp wherever an error occurs, and the programmer doesn't have to mark or wrap expressions in any special way to get this functionality. Which is crucial, because many of the situations in which this is useful are ones when you hit an error that you had no idea existed, and you certainly didn't know in advance where errors would occur.

Another Common Lisp feature that's very handy in this context is the ability to trigger an interrupt manually from the keyboard and end up in the same kind of break loop. Your program seems to be hung and you have no idea what it's doing? Interrupt it and look at the stack and the local variables. Everything looks okay but it's just taking a long time? Restart and you're back in action, continuing from where the interrupt occurred. If it doesn't look okay then examine the state to try to figure out what went wrong, abort the computation, fix the problem and re-run from the beginning.

My sense has been that this kind of functionality doesn't exist in any Clojure environment, maybe due to something about how the JVM works (about which I don't know very much, which may be very clear to all of you :-). But when I see fancy new conditional restart mechanisms etc. then I get a glimmer of hope that maybe I'm wrong about this.

So, can any existing libraries/systems in the Clojure ecosystem provide this functionality? Is it conceivable that any would in the future?

Thanks,

-Lee

Chris Zheng

unread,
Sep 27, 2013, 3:09:20 AM9/27/13
to clo...@googlegroups.com
Hey Lee.

I'm learning conditional restarts myself…. thus the reason why I implemented the library so I'm probably not the best person to ask

As far as I know… restarts have to be supported by the language itself in order for it to truly blossom the way you are describing it. ribol is just a library, not a platform and definitely not a development environment.

I'm not sure what the state is with https://github.com/pallet/ritz but I think that it may be what you are looking for in a development environment.

Chris.



zcaudate

unread,
Sep 27, 2013, 4:01:01 AM9/27/13
to clo...@googlegroups.com
Hi Dima,

I've push v0.2.3 to clojars... an example can be seen here: http://z.caudate.me/ribol/#raise-on

(raise-on [[NumberFormatException ArithmeticException] :divide-by-zero
           Throwable :throwing]
          (throw (Throwable. "oeuoeu"))
          (finally (println 1)))

=> (raises-issue {:throwing true}) ;; prints 1

Lee Spector

unread,
Sep 27, 2013, 10:32:21 AM9/27/13
to clo...@googlegroups.com

Thanks so much Chris.

I've started watching Hugo Duncan's ritz talk and it is definitely what I need to see.

It's funny because I never thought of this as platform or IDE functionality -- although it clearly is -- because in the Common Lisp world that I come from, some version of this is available universally as part of the language. You can do it whether you are running from a bare-bones terminal repl or from emacs or from some other IDE. The fancier environments can and do provide fancier interfaces and more options, but I think that the core functionality is everywhere.

I should finish watching Hugo's video before I say much more, but FWIW I think that ritz is exactly what I want except I'd want it ideally to be available from runs launched via "lein run" on the os command line. Or in Eclipse/CCW.

-Lee

Lee Spector

unread,
Sep 27, 2013, 11:08:35 AM9/27/13
to clo...@googlegroups.com

PS the rousing applause during Hugo's talk when he shows how you can view locals reminded me that I had seen this before, and indeed when I checked I remembered that I was even involved in a previous conversation about ritz-nrepl on this list. And I remember that the main obstacle to my happiness here is that this only seems to be available so far in emacs.

I guess that Common Lisp-style universality is probably not in the cards, but I think that getting this from from "lein run" would be a pretty good alternative. I say that not only because that's how I often run my code, but also because I guessing that many people, no matter their IDE preferences or how they usually run their code, could pretty easily do a "lein run" run if they knew that they needed to do some debugging. Even if that's not how you normally run your code it involves a lot less overhead than having to install/configure/learn/etc emacs if you just to see locals when an exception occurs.

-Lee
Reply all
Reply to author
Forward
0 new messages