unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Aborting debugger prompt
@ 2011-10-13 19:39 Tobias Gerdin
  2011-10-14  0:49 ` Ian Price
  2011-10-14  8:43 ` Andy Wingo
  0 siblings, 2 replies; 4+ messages in thread
From: Tobias Gerdin @ 2011-10-13 19:39 UTC (permalink / raw)
  To: guile-user

Hello,

When an error occurs and you are running under the REPL you are
dropped into the debugger ("Entering a new prompt. .."). This is
useful. But I am wondering if it is not possible to abort this prompt
with a user-defined value? That is, to get hold of the continuation
and applying it to some value so that the execution can continue from
the point of the error.

This would be convenient sometimes, and I guess this would be similar
to the Common Lisp "restarts" concept.

-Tobias



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

* Re: Aborting debugger prompt
  2011-10-13 19:39 Aborting debugger prompt Tobias Gerdin
@ 2011-10-14  0:49 ` Ian Price
  2011-10-14  8:43 ` Andy Wingo
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Price @ 2011-10-14  0:49 UTC (permalink / raw)
  To: Tobias Gerdin; +Cc: guile-user

Tobias Gerdin <tgerdin@gmail.com> writes:

> When an error occurs and you are running under the REPL you are
> dropped into the debugger ("Entering a new prompt. .."). This is
> useful. But I am wondering if it is not possible to abort this prompt
> with a user-defined value? That is, to get hold of the continuation
> and applying it to some value so that the execution can continue from
> the point of the error.

I agree, guile already supports R6RS exceptions, which may be
continued if called with raise-continuable, so it would be nice to be
able to use it at the debugger. The obvious thing to do would be to
extend the ,continue meta command so that we could do, say


scheme@(guile−user)> (+ 88 (raise-continuable 10))
<unnamed port>:43:6: In procedure #<procedure 8affc40 at <current input>:43:0 ()>:
<unnamed port>:43:6: ERROR: R6RS exception: `10'

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile−user) [1]> ,continue 10
$5 = 98


In the likely event that this undesirable to the guile implementers. A
somewhat less satisfying solution is to roll it yourself with
continuations, something like


;; WARNING: quick hack, may not perform as advertised
(use-modules (ice-9 control))

(define k #f)

(define (bad val)
  (shift c (begin (set! k c) (throw 'resumable val))))

(define (resume val)
  (k val))

scheme@(guile−user)> (+ 10 (bad 9))
<unnamed port>:154:2: In procedure #<procedure 93b9a10 at <current input>:154:2 (cont)>:
<unnamed port>:154:2: Throw to key `resumable' with args `(9)'.

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile−user) [1]> ,q
scheme@(guile−user)> (resume 8)
$7 = 18

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



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

* Re: Aborting debugger prompt
  2011-10-13 19:39 Aborting debugger prompt Tobias Gerdin
  2011-10-14  0:49 ` Ian Price
@ 2011-10-14  8:43 ` Andy Wingo
  2011-10-14 20:09   ` Ludovic Courtès
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2011-10-14  8:43 UTC (permalink / raw)
  To: Tobias Gerdin; +Cc: guile-user

Hi,

On Thu 13 Oct 2011 21:39, Tobias Gerdin <tgerdin@gmail.com> writes:

> When an error occurs and you are running under the REPL you are
> dropped into the debugger ("Entering a new prompt. .."). This is
> useful. But I am wondering if it is not possible to abort this prompt
> with a user-defined value? That is, to get hold of the continuation
> and applying it to some value so that the execution can continue from
> the point of the error.
>
> This would be convenient sometimes, and I guess this would be similar
> to the Common Lisp "restarts" concept.

Yes this would be useful.  In general you can't simply continue, as most
code that throws exceptions wouldn't work like that.  But you should be
able to ,return from any given frame on the stack.  You should also be
able to get a list of current restarts, and operate on them, as CL
does.  That would involve keeping a stack of restarts in a fluid,
somewhere in boot-9.

Patches are welcome :)

Andy
-- 
http://wingolog.org/



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

* Re: Aborting debugger prompt
  2011-10-14  8:43 ` Andy Wingo
@ 2011-10-14 20:09   ` Ludovic Courtès
  0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2011-10-14 20:09 UTC (permalink / raw)
  To: guile-user

Hey!

MIT/GNU Scheme provides a very nice user interface for this:

  1 ]=> foo

  ;Unbound variable: foo
  ;To continue, call RESTART with an option number:
  ; (RESTART 3) => Specify a value to use instead of foo.
  ; (RESTART 2) => Define foo to a given value.
  ; (RESTART 1) => Return to read-eval-print level 1.

  2 error> (restart 1)

  ;Abort!

  1 ]=> (+ 2 "foo")

  ;The object "foo", passed as the second argument to integer-add, is not the correct type.
  ;To continue, call RESTART with an option number:
  ; (RESTART 2) => Specify an argument to use in its place.
  ; (RESTART 1) => Return to read-eval-print level 1.

  2 error> (restart 2)


  New argument: 3

  ;Value: 5

Ludo’.




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

end of thread, other threads:[~2011-10-14 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-13 19:39 Aborting debugger prompt Tobias Gerdin
2011-10-14  0:49 ` Ian Price
2011-10-14  8:43 ` Andy Wingo
2011-10-14 20:09   ` Ludovic Courtès

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).