title: Parsing strings with Scheme
body: <p>I am trying to write a simple parser which creates a sxml-expression from a string, e. g.</p>
  
  <pre><code>"This is a [Test]" ===&gt; (item "This is a" (subitem "Test"))
  </code></pre>
  
  <p>Anybody who is wondering about the square brackets within the given example may have a look at the so called <a href="http://en.wikipedia.org/wiki/Leiden_Conventions" rel="nofollow">Leiden conventions</a>.</p>
  
  <p>This is the code I have written so far:</p>
  
  <pre><code>(define my-sequence '("this" "[" "is" "a" "]" "test"))
  
  (define (left-square-bracket? item)
    (or (equal? item "[")
        (eq? item #\x005b)))
  
  (define (right-square-bracket? item)
    (or (equal? item "]")
        (eq? item #\x005d)))
  
  (define (parse-sequence sequence)
    (cond ((null? sequence) '())
          ((left-square-bracket? (car sequence))
           (let ((subsequence (get-subsequence (cdr sequence))))
             (list subsequence)))
          (else
           (cons (car sequence)
                 (parse-sequence (cdr sequence))))))
  
  (define (get-subsequence sequence)
    (if (right-square-bracket? (car sequence))
        '()
        (cons (car sequence)
              (get-subsequence (cdr sequence)))))
  </code></pre>
  
  <p>Evaluating <code>(parse-sequence my-sequence)</code> yields <code>("this" ("is" "a"))</code>. A nested expression has been created, but the program finished without having evaluated the last item <code>"test"</code>. The question is, how do I return from <code>get-subsequence</code> to <code>parse-sequence</code>?</p>
  
  <p>Any help is appreciated, many thanks in advance! :)</p>