[racket] naming structs that are members of other structs
> I just figured that there is a thing in Racket coding style
> that bothers me from time to time. That thing have never arised
> in C-style languages.
Hi Dmitry,
I do run into this in C style languages too with regards to function
names. I can't have two functions named helper(), because one will
conflict with the other. In C, specifically, I have to add some
prefix at the beginning of public functions as a kludge to avoid
conflicts.
Most languages, though, will allow some kind of explicit namespacing
mechanism to let these compose and avoid the name conflicts. In
Racket, modules can be used as a namespacing mechanism.
Would you be able to put the structures in separate modules, and
namespace them using prefixes? For example:
;;;;;;;;;;;;;;;;;;;;;;;;;
#lang racket
(module VehicleState racket/base
(provide (all-defined-out))
(struct vehicle-state
(position velocity)))
(module Vehicle racket/base
(provide (all-defined-out))
(struct vehicle (state color model)))
(require (prefix-in vs: (submod "." VehicleState))
(prefix-in v: (submod "." Vehicle)))
vs:vehicle-state
v:vehicle-state
(eq? vs:vehicle-state v:vehicle-state)
;;;;;;;;;;;;;;;;;;;;;;;;;