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
This commit is contained in:
parent
188f080c79
commit
5faab8b578
|
@ -1,6 +1,6 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(provide debug)
|
(provide debug debugm)
|
||||||
|
|
||||||
;; printf debugging convenience
|
;; printf debugging convenience
|
||||||
(define-syntax debug
|
(define-syntax debug
|
||||||
|
@ -20,4 +20,17 @@
|
||||||
(printf "~a result was ~a~n" 'f (car e))
|
(printf "~a result was ~a~n" 'f (car e))
|
||||||
(printf "~a results were ~a~n" 'f e))
|
(printf "~a results were ~a~n" 'f e))
|
||||||
(apply values e))))]
|
(apply values e))))]
|
||||||
[(_ f . args) (debug (f . args))]))
|
[(_ 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)))]))
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
@title[#:tag "debug"]{Debugging}
|
@title[#:tag "debug"]{Debugging}
|
||||||
@(define the-eval (make-base-eval))
|
@(define the-eval (make-base-eval))
|
||||||
@(the-eval '(require unstable/debug))
|
@(the-eval '(require unstable/debug racket/match))
|
||||||
|
|
||||||
@defmodule[unstable/debug]
|
@defmodule[unstable/debug]
|
||||||
|
|
||||||
|
@ -23,3 +23,13 @@ Produce debugging output for the application of @racket[f], including the values
|
||||||
(debug + 1 2 3)
|
(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)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ Keep documentation and tests up to date.
|
||||||
@include-section["interval-map.scrbl"]
|
@include-section["interval-map.scrbl"]
|
||||||
@include-section["generics.scrbl"]
|
@include-section["generics.scrbl"]
|
||||||
@include-section["markparam.scrbl"]
|
@include-section["markparam.scrbl"]
|
||||||
|
@include-section["debug.scrbl"]
|
||||||
|
|
||||||
@;{--------}
|
@;{--------}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user