title: Clojure Structure Nested Within Another Structure
body: <p>Is it possible to have a structure nested within a structure in Clojure?  Consider the following code:</p>
  
  <pre><code>(defstruct rect :height :width)
  (defstruct color-rect :color (struct rect))
  
  (defn 
  #^{:doc "Echoes the details of the rect passed to it"}
  echo-rect
  [r]
    (println (:color r))
    (println (:height r))
    (println (:width r)))
  
  (def first-rect (struct rect 1 2))
  ;(def c-rect1 (struct color-rect 249 first-rect)) ;form 1
  ;output "249 nil nil"
  (def c-rect1 (struct color-rect 249 1 2)) ;form 2
  ;output "Too many arguments to struct constructor
  
  (echo-rect c-rect1)
  </code></pre>
  
  <p>Of course this is a contrived example but there are cases where I want to break a large data structure into smaller substructures to make code easier to maintain.  As the comments indicate if I do form 1 I get "249 nil nil" but if I do form 2 I get "Too many arguments to struct constructor".  </p>
  
  <p>If I'm approaching this issue in the wrong way, please tell me what I should be doing.  Searching the Clojure google group didn't turn up anything for me.</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>I guess I wasn't as clear in the statement of my question as I thought I was:</p>
  
  <p>1.) Is it possible to nest one struct within another in Clojure? (Judging from below that's a yes.)</p>
  
  <p>2.) If so, what would be the correct syntax be? (Again, judging from below it looks like there are a few ways one could do this.)</p>
  
  <p>3.) How do you fetch a value by a specified key when you've got a struct nested within another struct?  </p>
  
  <p>I guess my sample code didn't really demonstrate what I was trying to do very well.  I'm adding this here so that others searching for this might find this question and its answers more easily.</p>