That's quite elegant! > My tests suggest that this approach runs just a little slower than > continuation marks in Racket (which are deeply built in), and that's > good enough to get started.
Good to hear - I was somewhat worried that call/cc might be too slow for this purpose. > Longer term, I think something like this > approach could work and perform better as built into Chez; I've > experimented with that, but not conclusively. /Jens Axel 2017-02-23 13:02 GMT+01:00 Matthew Flatt <[email protected]>: > At Thu, 23 Feb 2017 10:04:16 +0100, Jens Axel Søgaard wrote: > > A technical issue: How do you plan to implement continuation marks? > > > > I see several options: > > > > i) adding continuation marks to Chez (tricky) > > ii) pass continuation marks along each function call using an extra > > argument (expensive) > > iii) code transformation (expensive?) > > > > Since Chez is "friendly" (provides TCO) is it possible to use a code > > transformation > > without a performance hit? > > Here's a sketch of how a `call/cm` function could work, relying on the > way that `eq?` works for detecting equivalent continuations in Chez: > > (define (call/cm key val proc) > ;; For this sketch, assumes `key` is always the same > (call/cc > (lambda (k) > (if (and (pair? stack) > (eq? k (caar stack))) > (begin > (set-cdr! (car stack) (cons key val)) > (proc)) > (begin0 > (call/cc > (lambda (k) > (set! stack (cons (cons k (cons key val)) > stack)) > (proc))) > (set! stack (cdr stack))))))) > > This approach causes the continuations that appear at the Racket level > to *not* be `eq?` when they're the same, because a continuation mark > can insert an extra frame (but only one per frame that would exist > otherwise). That loss seems ok, because Racket doesn't currently > provide an equality check on continuations. > > Besides making `with-continuation-mark` expand to call `call/cc`, all > the other control operators, like `call/cc` and `dynamic-wind`, need to > be wrapped to cooperate with it. Those wrappers are going to happen, > anyway, to implement delimited control. > > My tests suggest that this approach runs just a little slower than > continuation marks in Racket (which are deeply built in), and that's > good enough to get started. Longer term, I think something like this > approach could work and perform better as built into Chez; I've > experimented with that, but not conclusively. > > -- -- Jens Axel Søgaard -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CABefVgx_xki3RkFnFFH2BVi2ANpWMNffWSkhjvUa3MuS2QEWZQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
