From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: reporting 'system-error informatively Date: 21 Oct 2002 19:55:57 +0100 Sender: guile-user-admin@gnu.org Message-ID: References: <87r8ekx03e.fsf@zagadka.ping.de> <873cqzx33b.fsf@zagadka.ping.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1035227363 9830 80.91.224.249 (21 Oct 2002 19:09:23 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 19:09:23 +0000 (UTC) Cc: guile-user@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 183hvV-0002YB-00 for ; Mon, 21 Oct 2002 21:09:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 183hsY-0002VA-00; Mon, 21 Oct 2002 15:06:18 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 183hrV-0002HD-00 for guile-user@gnu.org; Mon, 21 Oct 2002 15:05:13 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 183hrP-00024O-00 for guile-user@gnu.org; Mon, 21 Oct 2002 15:05:10 -0400 Original-Received: from gnudist.gnu.org ([199.232.41.7]) by monty-python.gnu.org with esmtp (Exim 4.10) id 183hrO-00023m-00 for guile-user@gnu.org; Mon, 21 Oct 2002 15:05:06 -0400 Original-Received: from mail.uklinux.net ([80.84.72.21] helo=s1.uklinux.net) by gnudist.gnu.org with esmtp (Exim 4.10) id 183hrO-0004Xl-00 for guile-user@gnu.org; Mon, 21 Oct 2002 15:05:06 -0400 Original-Received: from laruns.ossau.uklinux.net (bts-0962.dialup.zetnet.co.uk [194.247.51.194]) by s1.uklinux.net (8.11.6/8.11.6) with ESMTP id g9LIxrb30866; Mon, 21 Oct 2002 19:59:54 +0100 Original-Received: from laruns.ossau.uklinux.net.ossau.uklinux.net (localhost [127.0.0.1]) by laruns.ossau.uklinux.net (Postfix on SuSE Linux 7.2 (i386)) with ESMTP id 1CA80DC4CC; Mon, 21 Oct 2002 19:55:58 +0100 (BST) Original-To: prj@po.cwru.edu (Paul Jarc) In-Reply-To: <873cqzx33b.fsf@zagadka.ping.de> Original-Lines: 67 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Errors-To: guile-user-admin@gnu.org X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.lisp.guile.user:1256 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:1256 >>>>> "Marius" == Marius Vollmer writes: >> Is there any way to get the arguments themselves, as plain Scheme >> values instead of text? Marius> Probably. Messing around with the 'stack' data structure is probably Marius> the right thing. Sorry, I can't say more. (But others might.) Assuming that `the-last-stack' has caught the error that you want to look at, you can get the stack object by (define s (fluid-ref the-last-stack)) and then the innermost stack frame by (define f (stack-ref s 0)) Now, a frame can be either an application or an evaluation, and you'll often find that the innermost frame is an application, with the one just higher being an evaluation, e.g. innermost: [string-length 4] 1 outer: (string-length 4) (frame-procedure? f) tells you whether the frame is an application. If it is, (frame-procedure f) returns the procedure and (frame-arguments f) returns the already evaluated args. If it isn't, (frame-source f) -- i.e. the frame is an evaluation -- returns the expression that was being evaluated, which is all you can get. So (untested as usual) ... (define (last-error->proc+args) (let* ((stack (fluid-ref the-last-stack)) (stacklen (stack-length stack))) (let loop ((index 0)) (if (< index stacklen) (let ((frame (stack-ref stack index))) (if (frame-procedure? frame) (values (frame-procedure frame) (frame-arguments frame)) (loop (+ index 1)))) #f)))) If `the-last-stack' hasn't captured the error that you want, you can capture it for yourself using `lazy-catch' and `make-stack': (define my-stack #f) (define (saving-error-to-my-stack proc) (define (lazy-handler key . args) (set! my-stack (make-stack #t lazy-handler)) (apply throw key args)) (lazy-catch #t proc lazy-handler)) Notes - (i) the `lazy-handler' in the `make-stack' call tells make-stack to return a stack object whose innermost frame is just outside the call into lazy-handler; (ii) the `#t' in the make-stack call means "here"; (iii) you must always rethrow from a lazy handler, hence the `(apply throw ...)' line. This should of course be in the manual. If anyone feels like working this into an appropriate patch, I'd appreciate it. Neil _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user