title: Functionally split a string by whitespace, group by quotes!
body: <p>Writing idiomatic functional code, in Clojure[1], how one would write a function that splits a string by whitespace but keeps quoted phrases intact? A quick solution is of course to use regular expressions but this should be possible without them. At a quick glance it seems pretty hard! I've written a similar in imperative languages but I'd like to see how a functional, recursive approach works.</p>
  
  <p>A quick checkout of what our function should do:</p>
  
  <pre><code>"Hello there!"  -&gt; ["Hello", "there!"]
  "'A quoted phrase'" -&gt; ["A quoted phrase"]
  "'a' 'b' c d" -&gt; ["a", "b", "c", "d"]
  "'a b' 'c d'" -&gt; ["a b", "c d"]
  "Mid'dle 'quotes do not concern me'" -&gt; ["Mid'dle", "quotes do not concern me"]
  </code></pre>
  
  <p>I don't mind if the spacing changes between the quotes (so that one can use simple splitting by whitespace first).</p>
  
  <pre><code>"'lots    of   spacing' there" -&gt; ["lots of spacing", "there"] ;is ok to me
  </code></pre>
  
  <p>[1] This question could be answered in general level but I guess that a functional approach in Clojure can be translated to Haskell, ML, etc with ease.</p>