private: No


(define trace--indent " ")

(define-syntax trace-lambda
  (syntax-rules ()
    ((_ name (args ...) body ...)
     (lambda (args ...)
       (define name
         (lambda (args ...)
           (for-each display (list trace--indent "(" (quote name)))
           (for-each display (list " " args)) ...
           (display ")\n")
           (let ((old-indent trace--indent)
                 (return
                  (begin
                    (set! indent (string-append trace--indent ": "))
                    body ...)))
             (set! trace--indent old-indent)
             (for-each display (list trace--indent return "\n"))
             return)))
       (name args ...)))))

(define-syntax trace-define
  (syntax-rules ()
    ((_ (name args ...) body ...)
     (define name (trace-lambda name (args ...) body ...)))))

(define-syntax trace-let
  (syntax-rules ()
    ((_ name ((keys values) ...) body ...)
     ((trace-lambda name (keys ...) body ...)  values ...))))

(define-syntax trace
  (syntax-rules ()
    ((_ exp) (let ((result exp)) (display exp) exp))))