Re:The Common Lisp Condition System – Upcoming Book
by phoe-krk on Wednesday July 15, 2020 @01:11PM
(#23848203)
Yes. Destructors are an equivalent of UNWIND-PROTECT, just like Java's finally{...} block of the try/catch/finally trio.
Thank you for mentioning Worlogog, I'll include that in the book. How should I credit you?
Re:The Common Lisp Condition System – Upcoming Book
by mst on Wednesday July 15, 2020 @01:33PM
(#23848582)
Not quite an equivalent in perl because there are limitations like exceptions being discarded if you're unwinding because of an exception being thrown, but it's entirely possible to make things go if you know what you're doing ;)
"Matt S. Trout (mst)" is good - I'm probably better known by my IRC nick than my full name in geek circles ;)
Re:The Common Lisp Condition System – Upcoming Book
by phoe-krk on Wednesday July 15, 2020 @01:40PM
(#23848708)
I'll keep that in mind, and I'll add that link to the book's contents, and I'll add you to my book's Hall of Fame. Thanks.
Re:The Common Lisp Condition System – Upcoming Book
by mst on Wednesday July 15, 2020 @01:52PM
(#23848931)
The author of Future::AsyncAwait is working on a patch to core to provide LEAVE {} blocks which will be a more full unwind-protect solution. Note of course the destructor limitation doesn't affect Worlogog use so much since you're -not- throwing exceptions, but once you're into mixed condition and exception based code of course things that to get more "fun".
Re:The Common Lisp Condition System – Upcoming Book
by phoe-krk on Wednesday July 15, 2020 @02:03PM
(#23849102)
> once you're into mixed condition and exception based code of course things that to get more "fun".
I imagine that is the reality of everyone who tries to implement a condition system in a language where the default behavior is to immediately unwind the stack by throwing some sort of an exception.
Re:The Common Lisp Condition System – Upcoming Book
by mst on Wednesday July 15, 2020 @11:51PM
(#23855583)
Yes. But as the only perler I've seen in this thread I wanted to do my best to be honest about the risks.
If I were to want to continue discussing this, do you happen to kick around anywhere on IRC that would be suitable?
Works for perl because while we don't (yet, somebody's working on one) have an unwind-protect like primitive, perl's refcounting system provides timely destruction so you can use a scope guard object stuffed into a lexical on the stack whose DESTROY method does whatever unwind cleanup you need.
Ironically, the main reason I'm not using this so much at the moment is that it isn't compatible with the suspend/resume code around promises provided by Future::AsyncAwait and I'm heavily using that in my current code, but at the point where I need both I'll probably attempt to nerd snipe one of the relevant authors into helping me figure it out.
(EDIT: Aaaaactually, I think I might already know how to make them work together, naturally an idea popped into my head just after I hit the post button ... using Syntax::Keyword::Dynamically and capturing a relevant future higher up the chain of calls should allow me to return-to-there cleanly, then I "just" need to cancel the intermediate futures to simulate unwinding ... but I'll have to try it to find out)