mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 20:30:28 +02:00
Add call/ec' and
let/ec'.
Based on a patch by Nala Ginrut <nalaginrut@gmail.com>, with suggestions from Mark H. Weaver. * module/ice-9/control.scm (call-with-escape-continuation, call/ec): New procedures. (let-escape-continuation, let/ec): New macros. * module/ice-9/futures.scm (let/ec): Remove. * test-suite/tests/control.test ("escape-only continuations")["call/ec", "let/ec"]: New tests. * doc/ref/api-control.texi (Prompt Primitives): Document `call/ec', `let/ec', and their long names.
This commit is contained in:
parent
d888b53168
commit
55e26a49db
4 changed files with 107 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
|||
;;;; -*- scheme -*-
|
||||
;;;; control.test --- test suite for delimited continuations
|
||||
;;;;
|
||||
;;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
||||
;;;; Copyright (C) 2010, 2011, 2013 Free Software Foundation, Inc.
|
||||
;;;;
|
||||
;;;; This library is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,6 +20,7 @@
|
|||
(define-module (test-suite test-control)
|
||||
#:use-module (ice-9 control)
|
||||
#:use-module (system vm vm)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (srfi srfi-11)
|
||||
#:use-module (test-suite lib))
|
||||
|
||||
|
@ -77,7 +78,32 @@
|
|||
(abort 'foo 'bar 'baz)
|
||||
(error "unexpected exit"))
|
||||
(lambda (k . args)
|
||||
args)))))
|
||||
args))))
|
||||
|
||||
(pass-if-equal "call/ec" '(0 1 2) ; example from the manual
|
||||
(let ((prefix
|
||||
(lambda (x lst)
|
||||
(call/ec
|
||||
(lambda (return)
|
||||
(fold (lambda (element prefix)
|
||||
(if (equal? element x)
|
||||
(return (reverse prefix))
|
||||
(cons element prefix)))
|
||||
'()
|
||||
lst))))))
|
||||
(prefix 'a '(0 1 2 a 3 4 5))))
|
||||
|
||||
(pass-if-equal "let/ec" '(0 1 2)
|
||||
(let ((prefix
|
||||
(lambda (x lst)
|
||||
(let/ec return
|
||||
(fold (lambda (element prefix)
|
||||
(if (equal? element x)
|
||||
(return (reverse prefix))
|
||||
(cons element prefix)))
|
||||
'()
|
||||
lst)))))
|
||||
(prefix 'a '(0 1 2 a 3 4 5)))))
|
||||
|
||||
;;; And the case in which the compiler has to reify the continuation.
|
||||
(with-test-prefix/c&e "reified continuations"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue