Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Toy Problem of the Week

Name: Anonymous 2009-12-12 18:22

I was raking around on the net and found this problem and coded up a solution. Once we get at least 10 solutions I'll post mine and a link to where I found the problem.
Any language, any libraries (but declare them) allowed. Aim for clarity and conciseness. Assume the input is well formed. Mine is 5 lines of scheme code (6 if we include requiring a library). No calling an "answer" function that "you wrote already and put in an external lib" ;)

Consider the problem of turning a list consisting
of a mix between symbols and non-symbols into a
list of lists of the symbol and its following
non-symbols. That is:

Input:    ({<symbol> <non-symbol>*} ... )
Output:   ((<symbol> (<non-symbol>*)) ...)
Example:     (a 1 2 3 b 4 5 c d 8 9 e)
           -> ((a (1 2 3)) (b (4 5)) (c ()) (d (8 9)) (e ()))

Name: OP 2009-12-12 22:00

My own solution was

(define (mk-sym-list lst)
  (if (null? lst) '()
      (let-values (((vals rest) (break symbol? (cdr lst))))
        (cons (list (car lst) vals)
              (mk-sym-list rest)))))

and it takes break from SRFI 1.
I came across this problem when reading a few old posts on jao's blog[1],  but the problem [linked to in the post] was from a comp.lang.scheme thread [2]

--References--
1. http://programming-musings.org/2006/02/07/scheme-code-kata/
2. http://groups.google.com/group/comp.lang.scheme/browse_frm/thread/09a1d9ab8b5d9c5e/62efc2529696d172#62efc2529696d172

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List