[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Scheme-reports] the humble pk
- To: scheme-reports <scheme-reports@x>
- Subject: [Scheme-reports] the humble pk
- From: Andy Wingo <wingo@x>
- Date: Mon, 19 Sep 2011 15:30:05 -0400
I apologize that this is not relevant to Scheme reports in general,
apart from having been motivated by the (define dummy (if #f #f)) idiom,
but this is a nice list.
In Guile we have a handy little debugging function, `pk'. It's my
;; peek takes any number of arguments, writes them to the
;; current ouput port, and returns the last argument.
;; It is handy to wrap around an expression to look at
;; a value each time is evaluated, e.g.:
;; (+ 10 (troublesome-fn))
;; => (+ 10 (pk 'troublesome-fn-returned (troublesome-fn)))
(define (peek . stuff)
(display ";;; ")
(car (last-pair stuff)))
(define pk peek)
The way it works is you just type `M-( p k SPC' in Emacs before your
squirrely expression, and you don't have to add dummy bindings. It
returns the last item in its args, so adding it to the RHS of a `let' is
If it were a macro I suppose that we could preserve the ability for the
last form to return multiple values, but oh well. It's a stupid little
function but I use it all the time.
What little functions do you use all the time when debugging?
Scheme-reports mailing list