() "Chris K. Jester-Young" <cky...@gmail.com> () Mon, 17 Sep 2012 10:01:33 -0400
(define (string-empty? str) (zero? (string-length str))) You can use ‘string-null?’ instead. (define* (regexp-split pat str #:optional (limit 0)) (let* ((result (fold-matches pat str '(0) regexp-split-fold 0 (if (positive? limit) (1- limit) #f))) (final (cons (substring str (car result)) (cdr result)))) (reverse! (if (zero? limit) (drop-while string-empty? final) final)))) Style nit: i find it easier to read ‘if’ expressions w/ the condition, then and else expressions on separate lines. Similarly ‘cons’. E.g.: (define* (regexp-split pat str #:optional (limit 0)) (let* ((result (fold-matches pat str '(0) regexp-split-fold 0 (if (positive? limit) (1- limit) #f))) (final (cons (substring str (car result)) (cdr result)))) (reverse! (if (zero? limit) (drop-while string-empty? final) final)))) It is easier because the eye can flowingly bump along the indentation w/o the doubtful mind jerking it to the right to fully identify and then verify forks and merges. Does that make sense? (If not, just ignore.) A more substantial line of questioning: What happens if ‘regexp-split’ is called w/ negative ‘limit’? Should that be handled in ‘regexp-split’ or will the procs it calls DTRT? What is TRT, anyway? In the absence of explicit validation, maybe a comment here will help the non-expert. -- Thien-Thi Nguyen ..................................... GPG key: 4C807502 . NB: ttn at glug dot org is not me . . (and has not been since 2007 or so) . . ACCEPT NO SUBSTITUTES . ........... please send technical questions to mailing lists ...........
pgpfX2fSt6oJJ.pgp
Description: PGP signature