Name: Anonymous 2008-11-08 13:21
I has it!
That is all.
That is all.
;Using SRFI 1 and SRFI 26
;Hangs if any of the strings is longer than max
(define (exercise/unsafe ss max)
(define (p)
(define m max)
(lambda (s) (set! m (- m (string-length s))) (>= m 0)))
(unfold null? (cut take-while (p) <>) (cut drop-while (p) <>) ss))
;Returns #f if any of the strings is longer than max
(define (exercise ss max)
(define (breaker)
(define m max)
(lambda (s) (set! m (- m (string-length s))) (>= m 0)))
(call-with-current-continuation
(lambda (k)
(unfold
(lambda (l) (or (null? l) (and (> (string-length (car l)) max) (k #f))))
(cut take-while (breaker) <>)
(cut drop-while (breaker) <>)
ss))))() considered invoking undefined behaviour, the rest of your code considered buggy and unreadable.