unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Hash table cursor with delimited continuations
@ 2015-10-01 13:56 Taylan Ulrich Bayırlı/Kammer
  2015-10-02  2:57 ` Mark H Weaver
  2015-10-03 21:21 ` Amirouche Boubekki
  0 siblings, 2 replies; 4+ messages in thread
From: Taylan Ulrich Bayırlı/Kammer @ 2015-10-01 13:56 UTC (permalink / raw)
  To: guile-user

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-03 21:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-01 13:56 Hash table cursor with delimited continuations Taylan Ulrich Bayırlı/Kammer
2015-10-02  2:57 ` Mark H Weaver
2015-10-02  6:53   ` Taylan Ulrich Bayırlı/Kammer
2015-10-03 21:21 ` Amirouche Boubekki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).