From 5faab8b578a35221571a3a894222e937f4fe0c68 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Thu, 20 May 2010 13:13:52 -0500 Subject: [PATCH] Add `debugm' to unstable/debug - `debugm' does not parse or print the arguments to the form, so it works for macros, not just function application --- collects/unstable/debug.rkt | 17 +++++++++++++++-- collects/unstable/scribblings/debug.scrbl | 12 +++++++++++- collects/unstable/scribblings/unstable.scrbl | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/collects/unstable/debug.rkt b/collects/unstable/debug.rkt index e4579c0746..fdc0fffec1 100644 --- a/collects/unstable/debug.rkt +++ b/collects/unstable/debug.rkt @@ -1,6 +1,6 @@ #lang racket/base -(provide debug) +(provide debug debugm) ;; printf debugging convenience (define-syntax debug @@ -20,4 +20,17 @@ (printf "~a result was ~a~n" 'f (car e)) (printf "~a results were ~a~n" 'f e)) (apply values e))))] - [(_ f . args) (debug (f . args))])) \ No newline at end of file + [(_ f . args) (debug (f . args))])) + +(define-syntax debugm + (syntax-rules () + [(_ kw . forms) + (begin (printf "starting ~a\n" 'kw) + (let ([e (with-handlers ([values (lambda (exn) + (printf "~a raised exception ~a~n" 'kw exn) + (raise exn))]) + (call-with-values (lambda () (kw . forms)) list))]) + (if (and (pair? e) (null? (cdr e))) + (printf "~a result was ~a~n" 'kw (car e)) + (printf "~a results were ~a~n" 'kw e)) + (apply values e)))])) \ No newline at end of file diff --git a/collects/unstable/scribblings/debug.scrbl b/collects/unstable/scribblings/debug.scrbl index 47c43caed3..6497001454 100644 --- a/collects/unstable/scribblings/debug.scrbl +++ b/collects/unstable/scribblings/debug.scrbl @@ -9,7 +9,7 @@ @title[#:tag "debug"]{Debugging} @(define the-eval (make-base-eval)) -@(the-eval '(require unstable/debug)) +@(the-eval '(require unstable/debug racket/match)) @defmodule[unstable/debug] @@ -23,3 +23,13 @@ Produce debugging output for the application of @racket[f], including the values (debug + 1 2 3) ] } + +@defform*[[(debugm f args ...)]]{ +Produce debugging output for the application of @racket[f], but does +not parse or print args. Suitable for use debugging macros. +@examples[#:eval the-eval +(debugm match (list 1 2 3) + [(list x y z) (+ x y z)]) +(debugm + 1 2 3) +] +} diff --git a/collects/unstable/scribblings/unstable.scrbl b/collects/unstable/scribblings/unstable.scrbl index 6a6289c86a..19b157a98e 100644 --- a/collects/unstable/scribblings/unstable.scrbl +++ b/collects/unstable/scribblings/unstable.scrbl @@ -94,6 +94,7 @@ Keep documentation and tests up to date. @include-section["interval-map.scrbl"] @include-section["generics.scrbl"] @include-section["markparam.scrbl"] +@include-section["debug.scrbl"] @;{--------}