2 comments

  • taeric2 hours ago
    I confess I like Common Lisp's TAGBODY far more than I feel like I should. Having constrained GOTO semantics to a short section of the codebase is surprisingly useful.
    • pmcgoron26 minutes ago
      From John Cowan:<p>TAGBODY doesn&#x27;t actually require continuations, delimited or undelimited, just proper tail calling. A macro can rewrite each section of the TAGBODY into a procedure nested within a `let` that tail-calls its successor, and the body of the `let` tail-calls the first procedure. (GO tag) is then equivalent to just (tag). This is a great way of doing state machines. Chicken has a tagbody egg, I think.
    • Joker_vD48 minutes ago
      Do you use it mostly as &quot;labeled breaks&quot; or to throw the values out of closures?
      • taeric43 minutes ago
        I haven&#x27;t used it much at all, to be clear. I just found it surprisingly fun the last few times I played with it.<p>The specific thing it made a lot easier was implementing algorithms the way that Knuth writes them down. Which is very much a set of steps with specific calls on what step to go to next.<p>I think the reason I found it fun to play with was that I found that style of laying out what needed to be done was easier to work with than the standard breakdown that making everything a function or an object seems to require. For me, it was a lot easier.<p>Edit: I have one of the times I used this here: <a href="https:&#x2F;&#x2F;taeric.github.io&#x2F;many_sums.html" rel="nofollow">https:&#x2F;&#x2F;taeric.github.io&#x2F;many_sums.html</a> I did not put any effort into cleaning up that code, though. So it can probably work as an argument in either direction. :D
    • kccqzy2 hours ago
      Constrained GOTO semantics sounds a lot like delimited continuations. Indeed I think Scheme continuations are a little too powerful for regular use by having the possibility of global effect (like longjmp). Delimited continuations make the effect more local.
      • taeric1 hour ago
        Delimited continuations always bounced off of me. In theory, they should be a lot like coroutines? I think, in practice, I just never really internalized all that goes into managing the current &quot;environment&quot; for a piece of code that is managed by the call state.<p>Like, I have a few partial mental models for everything that they pull together. I haven&#x27;t really tried to build on that, though. Should put some time to that.
        • mikkupikku1 hour ago
          You could implement coroutines with deliminated continuations, which is probably the best way to use deliminated continuations.
      • richdougherty1 hour ago
        If you&#x27;ll excuse the self-post, here&#x27;s a blog post on goto with delimited continuations.<p><a href="https:&#x2F;&#x2F;rd.nz&#x2F;2009&#x2F;03&#x2F;goto-in-scala.html" rel="nofollow">https:&#x2F;&#x2F;rd.nz&#x2F;2009&#x2F;03&#x2F;goto-in-scala.html</a><p>It uses an experimental compiler plugin for the Scala compiler. It&#x27;s typesafe at compile time. At runtime unfortunately it relies on exceptions for control flow.
  • umanwizard27 minutes ago
    Note that the example program:<p><pre><code> (define (displayln obj) (display obj) (newline)) (define cont #f) (displayln (call&#x2F;cc (lambda (k) (set! cont k) &quot;cont set&quot;))) (begin (displayln &quot;procedure called&quot;) (displayln &quot;after procedure call&quot;) (cont &quot;continuation called&quot;) (displayln &quot;after continuation call&quot;)) </code></pre> will only terminate if pasted into a REPL, not if invoked from a file.<p>This is because every top-level form in the REPL has an implicit continuation &quot;return to the REPL and read more input&quot;.<p>So after &quot;continuation called&quot; is printed, we go back to the prompt and await more input.<p>However, if this code is saved in a file and you run it (e.g. &quot;guile my-script.scm&quot;) then the continuation of the top-level `displayln` call is the top-level `begin` form, and we enter an infinite loop.