rename-out not working as expected

36 views
Skip to first unread message

David Storrs

unread,
Oct 12, 2021, 3:07:28 PM10/12/21
to Racket Users
---------------
; test.rkt
#lang racket
(define (do-something) "ok")
(provide do-something)

; test2.rkt
#lang racket
(require "test.rkt")
(provide (rename-out [do-something do-it]))

#lang racket
(require "test2.rkt")
do-it
---------------

The printed value is #<procedure:do-something> although I was expecting #<procedure:do-it>.  Have I done something wrong or simply misunderstood how rename-out works?

William J. Bowman

unread,
Oct 12, 2021, 3:14:32 PM10/12/21
to David Storrs, Racket Users
I think this is the expected behaviour of `rename-out`; you might want this library to change the dynamic displayed name:
https://docs.racket-lang.org/static-rename/index.html

--
William J. Bowman
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKodiRBWPK5MfgYnOi_V%2B%3DwwFzBxtQK1qV2Mj-zPuHEXn9g%40mail.gmail.com.

David Storrs

unread,
Oct 12, 2021, 3:25:15 PM10/12/21
to William J. Bowman, Racket Users
Okay, good.  Thanks for the library recommendation; I'll probably use that in the future where I need to rename/provide multiple things, but given that there's only one I did this instead in order to avoid having another dependency:

(provide do-it)
(define do-it (procedure-rename do-something 'do-i))

I suspect I'm reinventing the wheel and that's what static-rename compiles down to.


jackh...@gmail.com

unread,
Oct 14, 2021, 3:38:15 PM10/14/21
to Racket Users
static-rename compiles down to something totally different, actually. It uses the 'inferred-name syntax property to get the Racket compiler to choose a different name for the function at compile time. This is different from `(procedure-rename do-something 'do-i)`, which creates a wrapper function around the original. The 'inferred-name approach is guaranteed to have no runtime overhead.
Reply all
Reply to author
Forward
0 new messages