2010-01-31 00:02:00 +01:00
|
|
|
;;; Beyond call/cc
|
|
|
|
|
|
2011-04-28 12:17:56 +02:00
|
|
|
;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
2010-01-31 00:02:00 +01:00
|
|
|
|
|
|
|
|
;;;; This library is free software; you can redistribute it and/or
|
|
|
|
|
;;;; modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
;;;; License as published by the Free Software Foundation; either
|
|
|
|
|
;;;; version 3 of the License, or (at your option) any later version.
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; This library is distributed in the hope that it will be useful,
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
;;;; Lesser General Public License for more details.
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
;;;; License along with this library; if not, write to the Free Software
|
|
|
|
|
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(define-module (ice-9 control)
|
prompt, abort -> call-with-prompt, abort-to-prompt
* module/ice-9/boot-9.scm (default-prompt-tag, make-prompt-tag): New
functions.
(call-with-prompt, abort-to-prompt): Rename from `prompt' and `abort',
respectively. These names are more clear, and allow `prompt' and
`abort' to have more convenient, less general bindings.
(default-throw-handler, custom-throw-handler, catch, %start-stack):
Adapt callers.
* module/ice-9/control.scm: Adapt re-export list.
(control): Remove binding, until we're sure that it is Sitaram's
control.
(abort): New binding, aborts to the nearest prompt with the default
tag.
(%): Use call-with-prompt.
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
(*interesting-primitive-names*): Adapt for prompt/abort changes.
* test-suite/tests/control.test: Take advantage of the defaults for %
and abort.
2010-03-09 22:24:25 +01:00
|
|
|
#:re-export (call-with-prompt abort-to-prompt
|
|
|
|
|
default-prompt-tag make-prompt-tag)
|
2011-04-28 12:17:56 +02:00
|
|
|
#:export (% abort shift reset shift* reset*))
|
2010-01-31 00:02:00 +01:00
|
|
|
|
prompt, abort -> call-with-prompt, abort-to-prompt
* module/ice-9/boot-9.scm (default-prompt-tag, make-prompt-tag): New
functions.
(call-with-prompt, abort-to-prompt): Rename from `prompt' and `abort',
respectively. These names are more clear, and allow `prompt' and
`abort' to have more convenient, less general bindings.
(default-throw-handler, custom-throw-handler, catch, %start-stack):
Adapt callers.
* module/ice-9/control.scm: Adapt re-export list.
(control): Remove binding, until we're sure that it is Sitaram's
control.
(abort): New binding, aborts to the nearest prompt with the default
tag.
(%): Use call-with-prompt.
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
(*interesting-primitive-names*): Adapt for prompt/abort changes.
* test-suite/tests/control.test: Take advantage of the defaults for %
and abort.
2010-03-09 22:24:25 +01:00
|
|
|
(define (abort . args)
|
|
|
|
|
(apply abort-to-prompt (default-prompt-tag) args))
|
2010-01-31 00:02:00 +01:00
|
|
|
|
prompt as part of guile's primitive language
* libguile/control.h:
* libguile/control.c: Remove scm_atcontrol and scm_atprompt.
(scm_c_make_prompt): Remove handler arg, as the handler is inline.
(scm_abort): New primitive, exported to Scheme as `abort'. The
compiler will also recognize calls to `abort', but this is the base
case.
(scm_init_control): Remove scm_register_control, just have this
function, which adds `abort' to the `(guile)' module.
* libguile/eval.c (eval): Add SCM_M_PROMPT case.
* libguile/init.c (scm_i_init_guile): Change scm_register_control call
into a nice orderly scm_init_control call.
* libguile/memoize.h: (scm_sym_at_prompt, SCM_M_PROMPT):
* libguile/memoize.c (MAKMEMO_PROMPT, scm_m_at_prompt, unmemoize): Add
prompt support to the memoizer.
* libguile/vm-i-system.c (prompt): Fix to not expect a handler on the
stack.
* module/ice-9/boot-9.scm (prompt): Add definition in terms of @prompt.
* module/ice-9/control.scm: Simplify, and don't play with the compiler
here, now that prompt and abort are primitive.
* module/ice-9/eval.scm (primitive-eval): Add a prompt case.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Add @prompt and prompt.
2010-02-19 22:44:24 +01:00
|
|
|
(define-syntax %
|
|
|
|
|
(syntax-rules ()
|
2010-03-12 11:54:26 +01:00
|
|
|
((_ expr)
|
|
|
|
|
(call-with-prompt (default-prompt-tag)
|
|
|
|
|
(lambda () expr)
|
|
|
|
|
default-prompt-handler))
|
prompt as part of guile's primitive language
* libguile/control.h:
* libguile/control.c: Remove scm_atcontrol and scm_atprompt.
(scm_c_make_prompt): Remove handler arg, as the handler is inline.
(scm_abort): New primitive, exported to Scheme as `abort'. The
compiler will also recognize calls to `abort', but this is the base
case.
(scm_init_control): Remove scm_register_control, just have this
function, which adds `abort' to the `(guile)' module.
* libguile/eval.c (eval): Add SCM_M_PROMPT case.
* libguile/init.c (scm_i_init_guile): Change scm_register_control call
into a nice orderly scm_init_control call.
* libguile/memoize.h: (scm_sym_at_prompt, SCM_M_PROMPT):
* libguile/memoize.c (MAKMEMO_PROMPT, scm_m_at_prompt, unmemoize): Add
prompt support to the memoizer.
* libguile/vm-i-system.c (prompt): Fix to not expect a handler on the
stack.
* module/ice-9/boot-9.scm (prompt): Add definition in terms of @prompt.
* module/ice-9/control.scm: Simplify, and don't play with the compiler
here, now that prompt and abort are primitive.
* module/ice-9/eval.scm (primitive-eval): Add a prompt case.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Add @prompt and prompt.
2010-02-19 22:44:24 +01:00
|
|
|
((_ expr handler)
|
prompt, abort -> call-with-prompt, abort-to-prompt
* module/ice-9/boot-9.scm (default-prompt-tag, make-prompt-tag): New
functions.
(call-with-prompt, abort-to-prompt): Rename from `prompt' and `abort',
respectively. These names are more clear, and allow `prompt' and
`abort' to have more convenient, less general bindings.
(default-throw-handler, custom-throw-handler, catch, %start-stack):
Adapt callers.
* module/ice-9/control.scm: Adapt re-export list.
(control): Remove binding, until we're sure that it is Sitaram's
control.
(abort): New binding, aborts to the nearest prompt with the default
tag.
(%): Use call-with-prompt.
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
(*interesting-primitive-names*): Adapt for prompt/abort changes.
* test-suite/tests/control.test: Take advantage of the defaults for %
and abort.
2010-03-09 22:24:25 +01:00
|
|
|
(call-with-prompt (default-prompt-tag)
|
|
|
|
|
(lambda () expr)
|
|
|
|
|
handler))
|
2010-02-24 23:20:38 +01:00
|
|
|
((_ tag expr handler)
|
prompt, abort -> call-with-prompt, abort-to-prompt
* module/ice-9/boot-9.scm (default-prompt-tag, make-prompt-tag): New
functions.
(call-with-prompt, abort-to-prompt): Rename from `prompt' and `abort',
respectively. These names are more clear, and allow `prompt' and
`abort' to have more convenient, less general bindings.
(default-throw-handler, custom-throw-handler, catch, %start-stack):
Adapt callers.
* module/ice-9/control.scm: Adapt re-export list.
(control): Remove binding, until we're sure that it is Sitaram's
control.
(abort): New binding, aborts to the nearest prompt with the default
tag.
(%): Use call-with-prompt.
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
(*interesting-primitive-names*): Adapt for prompt/abort changes.
* test-suite/tests/control.test: Take advantage of the defaults for %
and abort.
2010-03-09 22:24:25 +01:00
|
|
|
(call-with-prompt tag
|
|
|
|
|
(lambda () expr)
|
|
|
|
|
handler))))
|
2010-03-12 11:54:26 +01:00
|
|
|
|
|
|
|
|
;; Each prompt tag has a type -- an expected set of arguments, and an unwritten
|
|
|
|
|
;; contract of what its handler will do on an abort. In the case of the default
|
|
|
|
|
;; prompt tag, we could choose to return values, exit nonlocally, or punt to the
|
|
|
|
|
;; user.
|
|
|
|
|
;;
|
|
|
|
|
;; We choose the latter, by requiring that the user return one value, a
|
|
|
|
|
;; procedure, to an abort to the prompt tag. That argument is then invoked with
|
|
|
|
|
;; the continuation as an argument, within a reinstated default prompt. In this
|
|
|
|
|
;; way the return value(s) from a default prompt are under the user's control.
|
|
|
|
|
(define (default-prompt-handler k proc)
|
|
|
|
|
(% (default-prompt-tag)
|
|
|
|
|
(proc k)
|
|
|
|
|
default-prompt-handler))
|
2011-04-28 12:17:56 +02:00
|
|
|
|
|
|
|
|
;; Kindly provided by Wolfgang J Moeller <wjm@heenes.com>, modelled
|
|
|
|
|
;; after the ones by Oleg Kiselyov in
|
|
|
|
|
;; http://okmij.org/ftp/Scheme/delim-control-n.scm, which are in the
|
|
|
|
|
;; public domain, as noted at the top of http://okmij.org/ftp/.
|
|
|
|
|
;;
|
2011-09-02 11:36:14 +02:00
|
|
|
(define-syntax-rule (reset . body)
|
|
|
|
|
(call-with-prompt (default-prompt-tag)
|
|
|
|
|
(lambda () . body)
|
|
|
|
|
(lambda (cont f) (f cont))))
|
2011-04-28 12:17:56 +02:00
|
|
|
|
2011-09-02 11:36:14 +02:00
|
|
|
(define-syntax-rule (shift var . body)
|
|
|
|
|
(abort-to-prompt (default-prompt-tag)
|
|
|
|
|
(lambda (cont)
|
|
|
|
|
((lambda (var) (reset . body))
|
|
|
|
|
(lambda vals (reset (apply cont vals)))))))
|
2011-04-28 12:17:56 +02:00
|
|
|
|
|
|
|
|
(define (reset* thunk)
|
|
|
|
|
(reset (thunk)))
|
|
|
|
|
|
|
|
|
|
(define (shift* fc)
|
|
|
|
|
(shift c (fc c)))
|