[racket] naming structs that are members of other structs

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Feb 14 13:13:24 EST 2013

Whenever I encounter this situation, I tend to switch to Racket's class system: 

(define vehicle 
 (class object% 

   (define vehicle-state 
      (class object% 
         (field position ;; 3D point 
                velocity ;; real
                )
         ...))

   (field state ;; vehicle-state
          color ;; color-string
          model ;; six-digit integer 
          )

   (define/public ...)))


This arrangement expresses the close association between vehicles and their state. 

If you wish to stay purely functional, the above is workable but it poses a few small obstacales. 



On Feb 13, 2013, at 3:38 PM, Dmitry Pavlov wrote:

> Danny, I would not treat this problem as similar to
> the helper() function name conflict you mentioned.
> Having two structures referring to each other
> in the same module is a much lesser sin than
> having two equally named things in the same module.
> 
> So I would prefer to solve this with a proper naming
> convention within a module, rather than putting each
> struct inside its own module.
> 
> 
> Stephen, thanks for the tip about the #:constructor-name.
> I think I may use that. Another solution, which just
> came to my head, is naming the structure
> vehicle/state instead of vehicle-state.
> 
> Best regards,
> 
> Dmitry
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.