[racket] struct constructor pitfalls

From: Anthony Carrico (acarrico at memebeam.org)
Date: Wed May 29 15:12:45 EDT 2013

It seems like the purpose of #:constructor-name is to get the default
contsructor out of the way, so you can customize it:

#lang racket

(struct hello (a b c)
  #:constructor-name hello-rep
  )

(define (hello) (hello-rep 1 2 3))

But this gives the error:
  duplicate definition for identifier in: hello

Work arounds:
 1. Use a guard, but this restricts the signature of the constructor.
 2. Use a module to manage the names, but this is annoying.
 3. Fall back on the make-hello convention instead of using the
    struct's name to construct it.

This is particularly painful if you have code that already uses a
default constructor name. You may want to change the struct's
representation, but now you can't emulate the old constructor. I guess
the forward looking programmer would always use the make-xxx convention
to avoid this pitfall. Am I missing anything?

-- 
Anthony Carrico

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.racket-lang.org/users/archive/attachments/20130529/78a294b3/attachment.sig>

Posted on the users mailing list.