guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hash table cursor with delimited continuations


From: Taylan Ulrich Bayırlı/Kammer
Subject: Hash table cursor with delimited continuations
Date: Thu, 01 Oct 2015 15:56:16 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Out of interest, I tried implementing a hash table cursor using
hash-for-each and delimited continuations:

    (use-modules
     (srfi srfi-9)
     (ice-9 hash-table))

    (define-record-type <ht-cursor>
      (make-cursor %cont key value)
      cursor?
      (%cont %cursor-cont)
      (key   cursor-key)
      (value cursor-value))

    (define ht-iter-prompt (make-prompt-tag "ht-iter"))

    (define (ht-cursor ht)
      (call-with-prompt
       ht-iter-prompt
       (lambda ()
         (hash-for-each
          (lambda (k v)
            (abort-to-prompt ht-iter-prompt k v))
          ht))
       (lambda (cont k v)
         (make-cursor cont k v))))

    (define (ht-cursor-next cursor)
      (call-with-prompt
       ht-iter-prompt
       (%cursor-cont cursor)
       (lambda (cont k v)
         (make-cursor cont k v))))

(The cursor would be valid so long as the table isn't mutated.)

But I hit the following problem:

scheme@(guile-user)> (define ht (alist->hash-table '((a . 0) (b . 1))))
scheme@(guile-user)> (define cursor (ht-cursor ht))
scheme@(guile-user)> (cursor-key cursor)
$2 = a
scheme@(guile-user)> (set! cursor (ht-cursor-next cursor))
ERROR: In procedure #<partial-continuation 1a24e00>:
ERROR: Throw to key `vm-error' with args `(vm-run "Unrewindable partial
continuation" (#<vm-continuation 1c7b270>))'.

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]>


I couldn't find any direct documentation about this, only some mentions
of "rewindable" flags in the C API in (info "(guile) Dynamic Wind").

Is it a bug, or an undocumented limitation?..  I don't know what I
should generally expect when using delimited continuations with Guile
APIs implemented in C such as hash-for-each.

Thanks in advance,
Taylan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]