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

Haskell Homework Project

Name: Anonymous 2008-11-08 13:21

I has it!

That is all.

Name: Anonymous 2008-11-11 18:40

;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))))


>>22
() considered invoking undefined behaviour, the rest of your code considered buggy and unreadable.

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