7 ms·
Show HN: My book, The Common Lisp Condition System
- phoe-krk 6y agoAuthor here. The Common Lisp Condition System is my first book and it was previously discussed on Hacker News[0] as soon as the Apress page for the book was first posted. The HN discussion was very fruitful and insightful and prompted me to add more content about the condition system in general. Due to time constraints and the flow of working on the book, it was impossible to add this new stuff to the actual body of the book, so me and Apress have decided to publish this content as an appendix named Discussing the Common Lisp Condition System and release it[1] on the Internet. The appendix is free to download and use in any way and I'd like to once again thank everyone who participated in the original thread. The book is currently available for purchase on Apress[2] (with chapter samplers) and Amazon[3]. The full source code is available on GitHub[4] and should be buildable under any conforming C compilers and any conforming Common Lisp implementations. I'm available for answering any questions about it and merging any PRs that might arrive. I hope that the book is helpful in general and wish everyone who decides to try it a good read. AMA. [0] https://news.ycombinator.com/item?id=23843525 https://news.ycombinator.com/item?id=23843525 [1] https://github.com/Apress/common-lisp-condition-system/blob/master/Appendix%20E/Appendix%20E.pdf https://github.com/Apress/common-lisp-condition-system/blob/... [2] https://www.apress.com/us/book/9781484261330 https://www.apress.com/us/book/9781484261330 [3] https://www.amazon.com/Common-Lisp-Condition-System-Mechanisms/dp/148426133X https://www.amazon.com/Common-Lisp-Condition-System-Mechanis... [4] https://github.com/Apress/common-lisp-condition-system https://github.com/Apress/common-lisp-condition-system
- db48x 6y agoThat's a really impressive way of both continuing the conversation and sneaking in extra improvements to your book!
- phoe-krk 6y agoThanks. The only thing that is sad to me is that this content did not make it into the book itself. (I guess that I can be proud of myself though: the first edition of the book wasn't even out of production and I already had some stuff written for the second edition.)
- oalae5niMiel7qu 6y agoThere's an issue with 4.6.8: You can't use saved images to debug errors in SBCL, because SBCL's SAVE-LISP-AND-DIE function throws the stack away.
- phoe-krk 6y agoYes, this last fact is explicitly mentioned in the last two sentences of this section. > Another issue is preserving the state of the program stack, as it is destroyed in the process of dumping the Lisp image, and it cannot be fully restored when the image is thawed. However, portability libraries such as Dissect[0] allow for saving the stack state as normal Lisp data that can then be inspected using the system inspector. [0] https://shinmera.github.io/dissect/ https://shinmera.github.io/dissect/ Still, you can fully preserve the full stack information as Lisp data along with the whole heap, dump the image, and then inspect the dumped core as if you inspected any other Lisp image. This is already a big quality improvement over digging in dead crash dumps or - worse - textual, printed stacktraces with no other information available. Therefore, I think that the statement "you can't use saved images to debug errors in SBCL" is somewhat far-fetched, really.
- dreamcompiler 6y agoJust bought it. Thanks for writing this, and thanks for your continuing participation in discussions of CCL issues on github.
- phoe-krk 6y agoThank you; I hope that I will find and allocate enough time in the nearby future to help with maintaining CCL some more.
- javert 6y agoIf anyone else is wondering what the Lisp "condition system" is... Apparently it's analogous to "exception handling" in other languages, but with some extra features. Props to the author for getting out his first book!
- phoe-krk 6y agoNot exactly. The Common Lisp condition system is usable for handling error situations, but it's usable for much more as well; the act of signaling a condition does not immediately unwind the stack, like throwing an exception does, and the restart system allows for actively choosing which pieces of dynamically provided code should be run instead of just blindly executing them in order. This allows for some extra flexibility with regard to how to handle errors, and with regard to how conditions may be used without any unwinding whatsoever. (Thanks for the props!)
- minerjoe 6y agoIt's not that "analogous". Take a peek, it doesn't unwind the stack unless you ask it to, which gives it much more power than exception handling in languages such as Java.
- outworlder 6y agoThat's the problem with Lisp features - you don't get to appreciate how powerful they are until you are way deep in the woods, at which point you are now another 'convert' trying to convince others to follow. I like Scheme but having seen what the condition system could do on Lisp Machines decades ago makes me feel like we are currently living in a computing dark ages.
- phoe-krk 6y agoI sincerely hope that my book aids this problem that you are speaking of - both by allowing programmers and implementers of other languages use the techniques that originate in Lisp, and to try and bash at the Lisp-as-a-meme prejudice that I've seen in many places by showing what the condition system is actually useful for.
- flubert 6y agoIs this targeted more at users of the condition system, or implementers who are writing their own common lisp compilers? From the Amazon blurb: >In part 1 of The Common Lisp Condition System, the author introduces the condition system using a bottom-up approach, constructing it piece by piece. He uses a storytelling approach to convey the foundation of the condition system, dynamically providing code to alter the behavior of an existing program. Later, in part 2, you’ll implement a full and complete ANSI-conformant condition system while examining and testing each piece of code that you write.
- phoe-krk 6y agoBoth. The book contains an explanation of how to derive the condition system from the primitive operators of Common Lisp, which should be useful both for users that try to gain some intuition or broaden their understanding of how the condition system works under the hood, and for people who want to implement a condition system in a programming language without one - be it Common Lisp or a different language. Implementing a condition system in a Common Lisp implementation is actually a mostly solved problem, since one can use e.g. https://github.com/phoe/portable-condition-system https://github.com/phoe/portable-condition-system or borrow some code from an already working Common Lisp implementation.
- nickdrozd 6y agoTo what extent is the CL condition system inherently tied to Lisp(s)? Is there anything about it that makes it a natural fit for Lisp but not for other languages? Macros, for example, are a natural fit for Lisp because of the parentheses. It would be difficult to add Lisp-style macros to a language like Python because Python doesn't have Lisp parentheses. In contrast, there's nothing about multiple namespaces that is particularly tied to Lisp. Common Lisp and Emacs Lisp have multiple namespaces, but Scheme doesn't. Python doesn't have them, but it just as easily could. So is the condition system more like macros or more like multiple namespaces?
- phoe-krk 6y agoIt is the latter. It is possible to implement a condition system on top of any language that has dynamic variables, a `finally`-style construct and some mechanism for unwinding the stack. Since dynamic variables are implementable on top of lexical variables and `finally`, it's basically just about unwinding the stack and `finally`. The main issue is how a condition system would fit with any existing system which likely works by immediately unwinding the stack rather than allowing to wind it further; that's the case e.g. in Java or C++.
- jbjohns 6y agoIsn't it possible to do in any system with CPS as well? I've not tried it but I would expect to be able to have a "conditions system" using the CPS monad in Haskell, for example. And Haskell doesn't even have variables the way most programmers think of them.
- phoe-krk 6y agoI haven't explored the CPS topic deeply, so I cannot really answer. As far as I understand, CPS preserves the state of the program or stack information by storing it in closures that are ready to be called at any time, whereas a condition system simply does not unwind the stack by simply not unwinding it and executing on top of the already existing stack, ready to both return control to the signaling code and to transfer it somewhere up the stack. In its nature, a condition system is simply a means of executing code that has been provided dynamically, including transfers of control. I think that a closer term would be algebraic effects, which seem to be an equivalent of a condition system in a strictly typed strictly functional world.
- db48x 6y agoI think section 4.11 is the most important of the new material.
- phoe-krk 6y agoThank you. I am taking a big risk by making the statement in 4.11 (in the online Appendix E), since it directly implies that none of C++, Java, Python et al actually do any exception handling at all. It's all control flow, always has been. Still, I've actually wanted to write it there since I considered it to be important, and because that argument came into existence during the first Hacker News discussion about the book (and therefore is a product of more than just my mind).
- db48x 6y agoYou are kind of implying that :) It may come down to how we actually use exceptions in those languages, however, that makes the difference. I worked on a system written in PHP + Bash which had been built to have some restartability. It was a horrible kludge, and to improve the system you had to pore over the logs to try to divine what had happened, but there was an attempt.
- phoe-krk 6y agoYes, I'm implying that. For instance, a lot of Python's use of "throw" is not really because we want to signal an exception in some Python code, we just want to unwind the stack while passing some values and we can't do it in any other way in the language. Again, that's just control flow, and that's because throwing exceptions is the only way of performing non-local exits in those languages. Actual exception handling starts when the existing control flow cannot handle some situation that has occurred, and someone - or something - needs to be able to create new control flow dynamically in order to continue program execution and therefore the process that was ongoing there. Or, you know, we can do the industry standard: crash the program, and restart the thread or daemon or virtual machine or server cluster in question in hope that turning it off and on again helps. /s
- hoytech 6y agoCongrats! The condition system isn't very well described elsewhere, especially relative to how cool it is. I just ordered your book, looking forward to reading it.
- phoe-krk 6y agoThank you for the congrats, and the fact that it wasn't described anywhere is the reason for my original frustration, which in turn is the reason why this book exists. I hope that the book is useful for you; in case of any questions, please feel free to ask me and/or make issues on the GitHub repository of the book. In the worst case, I'll create or expand the book's errata... or write yet another appendix.
- gibsonf1 6y agoJust bought it - Thanks!!!
- phoe-krk 6y agoThanks, hope that it serves you well.
- rlonstein 6y agoCongratulations! My copy arrived yesterday!
- phoe-krk 6y agoThank you! I hope that it serves you well.