title: Level out a list of lists
body: <p>I'm trying to level out in Racket a list made out of lists and list of lists. The original list looks like:</p>
  
  <pre><code>'(((a 1) (b 2)) (c 3) ((d 4) (e 5)))
  </code></pre>
  
  <p>I need it to be like:</p>
  
  <pre><code>'((a 1) (b 2) (c 3) (d 4) (e 5))
  </code></pre>
  
  <p>I've tried with flatten, concatenate, etc and I get different things but not this one:</p>
  
  <pre><code>(define KK '(((a 1)(b 2))(c 3)((d 4)(e 5))))
  
  (map(lambda(x)(if (list? x) x (list x)))(concatenate KK))
  
  '((a 1) (b 2) (c) (3) (d 4) (e 5))
  
  (map(lambda(x)x)(concatenate KK))
  
  '((a 1) (b 2) c 3 (d 4) (e 5))
  
  (map(lambda(x)(if (list? (car x)) (ormap(lambda(y)(when (list? y) y)) x) x))KK)
  
  '((a 1) (c 3) (d 4))
  
  (map(lambda(x)(if (list? (car x)) (andmap(lambda(y)(when (list? y) y)) x) 
  x))KK)
  
  '((b 2) (c 3) (e 5))
  </code></pre>
  
  <p>The closer I got is the last two, but I have missing values, because it is a boolean map. Map packs the result in a single list.</p>
  
  <p>EDIT: My main problem is that the list is created by a function that depending on the input, the output is a single list or a list of 2 to n lists:</p>
  
  <p>Let a list called H be composed of 2 to n elements. Let SPECS be a list made out of lists with the possible combinations of the elements of H that matches condition C. For example:</p>
  
  <pre><code>H='(a 1)
  </code></pre>
  
  <p>So, being '* a symbol that semantically means a wild car, let all combinations of elements in H to be:</p>
  
  <pre><code>HHs='((* *) (a *)(* 1) (a 1))
  </code></pre>
  
  <p>So SPECS are the HHs that meets some conditions, for example: '((a <em>)(</em> 1))</p>
  
  <pre><code>(map (lambda(S)(when  (&lt;condition&gt;)(set! NEWSET (append NEWSET S))))SPECS)
  </code></pre>
  
  <p>If I trace S I see this:</p>
  
  <pre><code>S1: (((*) (-inf.0 9) (2 +inf.0) (*)) ((*) (9 30) (2 +inf.0) (*)))
  S2: ((*) (-inf.0 30) (2 +inf.0) (*))
  S3: (((*) (-inf.0 30) (2 +inf.0) (no)) ((*) (-inf.0 30) (2 +inf.0) (si)))
  S4: (((soleado) (-inf.0 30) (*) (*)) ((nublado) (-inf.0 30) (*) (*)) ((lluvioso) (-inf.0 30) (*) (*)))
  </code></pre>
  
  <p>So if I pack them in a list, I have:</p>
  
  <pre><code>'((((*) (-inf.0 9) (2 +inf.0) (*)) ((*) (9 30) (2 +inf.0) (*)))
     ((*) (-inf.0 30) (2 +inf.0) (*))
     (((*) (-inf.0 30) (2 +inf.0) (no)) ((*) (-inf.0 30) (2 +inf.0) (si)))
     (((soleado) (-inf.0 30) (*) (*)) ((nublado) (-inf.0 30) (*) (*)) ((lluvioso) (-inf.0 30) (*) (*))))
  </code></pre>
  
  <p>But I would need instead:</p>
  
  <pre><code>'(((*) (-inf.0 9) (2 +inf.0) (*)) ((*) (9 30) (2 +inf.0) (*))((*) (-inf.0 30) (2 +inf.0) (*))((*) (-inf.0 30) (2 +inf.0) (no)) ((*) (-inf.0 30) (2 +inf.0) (si))((sunny) (-inf.0 30) (*) (*)) ((cloudy) (-inf.0 30) (*) (*)) ((rainy) (-inf.0 30) (*) (*)))
  </code></pre>
  
  <p>(having the elements of the lists in () it's just a semantic of my algorythm).</p>
  
  <p>Regards</p>