TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Restarts in Common Lisp

139 pointsby sulamiabout 5 years ago

15 comments

phoe-krkabout 5 years ago
Nitpick:<p>&gt; While Common Lisp calls them “conditions”, I will stick with “error” in this post, because I don’t think “condition” is very self-explanatory if you’re not familiar with the language already. Please forgive my inaccuracy.<p>This is misleading. It is possible to signal conditions that are not errors, and therefore do not require stack unwinding, like errors do. The condition facility allows one to execute arbitrary code with arbitrary arguments at the SIGNAL site.<p>`SIGNAL` walks the list of condition handlers and executes the type-matching ones in order of their binding. If a handler returns normally, then next ones are executed; if all matching handlers are exhausted, `SIGNAL` returns, and code execution continues.<p><pre><code> CL-USER&gt; (handler-bind ((condition (lambda (c) (format t &quot;;; Foo: ~A~%&quot; c))) (condition (lambda (c) (format t &quot;;; Bar: ~A~%&quot; c))) (condition (lambda (c) (format t &quot;;; Baz: ~A~%&quot; c)))) (signal &#x27;condition) 42) ;; Foo: Condition CONDITION was signalled. ;; Bar: Condition CONDITION was signalled. ;; Baz: Condition CONDITION was signalled. 42 </code></pre> Of course, a handler can perform a non-local transfer of control elsewhere, e.g. by using `GO` or `THROW`. In such a case, control is transferred out of `SIGNAL`, so next handlers are - naturally - not invoked.<p>While I understand that this post is trying to appeal to language newcomers, simplifying the whole condition system to an &quot;error try-catch&quot; is a drastic misrepresentation of the condition system that will leave the newbies with the impression that that&#x27;s all that is possible with that feature. Since it seems that the author is a Lisp newcomer as well (which I wholeheartedly admire! :), I&#x27;d advise him to use the original notation of &quot;condition&quot;, instead for the one of &quot;error&quot;.
评论 #22750062 未加载
评论 #22751309 未加载
评论 #22752664 未加载
aidenn0about 5 years ago
Aside from restarts, the core difference between the Common Lisp condition system and exceptions in most other languages is that the exception handler can run before the stack is unwound.<p>Having the call-stack available at the time the handler runs can be very useful; many modern dynamic languages will save some of that information in the exception object. It&#x27;s still surprising to me that so very few languages have copied this feature (or even independently discovered it).
评论 #22749295 未加载
评论 #22749148 未加载
评论 #22750851 未加载
评论 #22753820 未加载
chaitanyaabout 5 years ago
Many years ago I wrote about restarts in CL using the example of a CSV parser: <a href="https:&#x2F;&#x2F;lisper.in&#x2F;restarts" rel="nofollow">https:&#x2F;&#x2F;lisper.in&#x2F;restarts</a><p>Fun fact: the restarts based CSV parser was based on some real world work me and a colleague had done for an online travel portal. I wrote about it here: <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;lisp&#x2F;comments&#x2F;7k85sf&#x2F;a_tutorial_on_conditions_and_restarts&#x2F;drceozm&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;lisp&#x2F;comments&#x2F;7k85sf&#x2F;a_tutorial_on_...</a>
metroholografixabout 5 years ago
I find that Practical Common Lisp has not aged well. Maybe it&#x27;s the &quot;practical&quot; part with the specific examples the author used -that are now terribly dated- that is mainly responsible, but the end result is that I no longer recommend it.<p>My goto recommendation for newcomers is Norvig&#x27;s PAIP which is full of insightful moments and unbelievably good code and for people with more experience &quot;Let over Lambda&quot; by Doug Hoyte, which is a mind-blowing book mainly because of the time-transcendent nature of the examples Doug chose.
评论 #22749257 未加载
评论 #22748453 未加载
评论 #22749204 未加载
评论 #22748467 未加载
评论 #22752468 未加载
评论 #22748370 未加载
评论 #22756890 未加载
kazinatorabout 5 years ago
In TXR Lisp, I unified condidtions and restarts into one thing: exceptions. By programmer convention only, restarts are exceptions derived from <i>restart</i>.<p>The documentation has dialect notes about this with a comparative example:<p><a href="https:&#x2F;&#x2F;www.nongnu.org&#x2F;txr&#x2F;txr-manpage.html#N-00F77525" rel="nofollow">https:&#x2F;&#x2F;www.nongnu.org&#x2F;txr&#x2F;txr-manpage.html#N-00F77525</a>
artemonsterabout 5 years ago
Can somebody please also elaborate what is the difference between condition system in CL and &quot;new thing&quot; algebraic effect handlers? On the surface I see no difference, other that the latter is being a more formalized version of conditions? But we have same properties: 1. signal a condition to some handler(s), possibly with value. 2. reify the stack into a (delimited up to level with handler) continuation and let handler decide what to do with it: save, restart, resume with some value. Am I missing something?
评论 #22753828 未加载
评论 #22749212 未加载
jgrant27about 5 years ago
<a href="https:&#x2F;&#x2F;imagine27.com&#x2F;error-handling-or-the-emporors-old-clothes" rel="nofollow">https:&#x2F;&#x2F;imagine27.com&#x2F;error-handling-or-the-emporors-old-clo...</a>
mrow84about 5 years ago
A long time ago I wrote a conditions system for python: <a href="https:&#x2F;&#x2F;code.google.com&#x2F;archive&#x2F;p&#x2F;pyconditions&#x2F;" rel="nofollow">https:&#x2F;&#x2F;code.google.com&#x2F;archive&#x2F;p&#x2F;pyconditions&#x2F;</a><p>I wouldn&#x27;t recommend using it, but it is an interesting error&#x2F;control model, and I always wondered why it hasn&#x27;t seen wider implementation - I presume because it is closer to the &quot;dangerous&quot; end of the power spectrum.
olah_1about 5 years ago
Hey Sulami, this is off topic, but how did you get those nice sidebar footnotes? What theme are you using? Or how did you edit the css?
评论 #22748303 未加载
评论 #22748300 未加载
nabla9about 5 years ago
The condition system in Common Lisp is really amazing piece of work. Error and exception handling is just subclass of larger set of possible uses called conditions.
shadowgovtabout 5 years ago
Interesting. This looks like an implementation of the abstract computer science notion of continuations (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continuation);" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Continuation);</a> neat to see them used this way.
评论 #22754483 未加载
评论 #22752497 未加载
nickpsecurityabout 5 years ago
With a quick DuckDuckGo-ing, I found this intro to be really understandable compared to most links I read:<p><a href="https:&#x2F;&#x2F;z0ltan.wordpress.com&#x2F;2016&#x2F;08&#x2F;06&#x2F;conditions-and-restarts-in-common-lisp&#x2F;" rel="nofollow">https:&#x2F;&#x2F;z0ltan.wordpress.com&#x2F;2016&#x2F;08&#x2F;06&#x2F;conditions-and-resta...</a>
nerdponxabout 5 years ago
R, continuing its theme of being a weird Lisp with C syntax and really bad function names, has a condition system: <a href="https:&#x2F;&#x2F;adv-r.hadley.nz&#x2F;conditions.html" rel="nofollow">https:&#x2F;&#x2F;adv-r.hadley.nz&#x2F;conditions.html</a>
slifinabout 5 years ago
Keep meaning to look at this, Clojure has some libraries for this I could use:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;clojureman&#x2F;special#alternative-libraries" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;clojureman&#x2F;special#alternative-libraries</a>
kazinatorabout 5 years ago
The author doesn&#x27;t seem to understand that not all exceptional situations are errors, which suggests he is a complete newbie to exception handling, which explains why he didn&#x27;t propose the word &quot;exception&quot; instead of &quot;condition&quot;.
评论 #22751909 未加载
评论 #22751901 未加载