title: How can I count the number of elements in a list tree in Racket?
body: <p>I am going over some racket exercises, and one of these exercises asks to create a function called "count-trees" that will count all the elements in a ListTree. Per the instructions, a ListTree is a recursive data structure with the following definition(s):</p>
  
  <p>-It can be an integer</p>
  
  <p>-It can be a list or a list with sublists</p>
  
  <p>-Per the instructions, we assume that a list tree can never be empty</p>
  
  <p>Here are a few examples of what a List Tree looks like: </p>
  
  <pre><code>(list 1 2)
  
  (list (list 1)
         2
        (list 1 4 5))
  
  (list 1
         (list 2 1)
          1
          1)
  </code></pre>
  
  <p>Now, here is what my code looks like:</p>
  
  <pre><code>(define count-tree (lambda (lst)
                     (if (empty? lst)
                         0
                         (length (lst)))))
  </code></pre>
  
  <p>When I execute the function, it works but only when there is one list, not on lists that contain sub-lists. It seems to only count how many lists there are, but I want it to count all elements in the list. Is there a way to go about this? Thanks!</p>