[racket] Procedure name printing in DrRacket

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Mon Apr 16 18:09:36 EDT 2012

Small followup: we can do something like the following to let Racket
do most of the hard work.

;; A little syntax to bind the name that Racket is inferring in the
surrounding context.
(define-syntax (with-inferred-name stx)
  (syntax-case stx ()
    [(_ id body)
     (let ([an-inferred-name (syntax-local-name)])
       #`(let ([id '#,an-inferred-name])

;; Now let's make another version of make-add-suffix-2 that
;; picks up the inferred name and uses it:
(define (make-add-suffix-2 a-proc-name s2)
  (procedure-rename (lambda (s) (string-append s s2))

;; We define stronger-2 by using with-inferred-name:
(define stronger-2
  (with-inferred-name proc-name
                      (make-add-suffix-2 proc-name "!")))

This uses a small macro feature (syntax-local-name) to let the
compiler expose the name that Racket would use if it were in a
position to define a value.

Posted on the users mailing list.