[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Scheme-reports] the humble pk



Hello all,

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

    ;; 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)
      (newline)
      (display ";;; ")
      (write stuff)
      (newline)
      (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
very natural.

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?

Regards,

Andy
-- 
http://wingolog.org/

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports