Defining a function with the same name as a struct with a different constructor name

30 views
Skip to first unread message

flirora

unread,
Jun 3, 2021, 5:01:51 PM6/3/21
to Racket Users

Am I correct in assuming that given a definition like

(struct foo (x) #:constructor-name bar)

I then can't define something named foo in the same module, even though there's no constructor called foo?

Sage Gerard

unread,
Jun 3, 2021, 5:04:50 PM6/3/21
to racket...@googlegroups.com

My understanding is that you can shadow `foo`, but you cannot use `foo` in any expression at the same scope where the struct's bindings appear. In this context, some of `foo`'s lexical information is reserved so that `struct-out` works correctly.

--
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/02598ee4-4461-4815-bd4f-a8ac02c1118cn%40googlegroups.com.
--
~slg

Shu-Hung You

unread,
Jun 3, 2021, 5:26:57 PM6/3/21
to Sage Gerard, Racket Users
In addition to the constructor, `foo` is also used for compile-time
struct information. To avoid this, either supply #:name to designate a
different identifier for compile-time struct type information, or
declare #:omit-define-syntaxes to dismiss it.

Shu-hung
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/76c51dda-b80d-d74a-c691-d92fe11008e8%40sagegerard.com.

flirora

unread,
Jun 4, 2021, 4:23:20 PM6/4/21
to Racket Users
Thanks for the answers!
Reply all
Reply to author
Forward
0 new messages