[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regexp-split for Guile
From: |
Thien-Thi Nguyen |
Subject: |
Re: regexp-split for Guile |
Date: |
Mon, 17 Sep 2012 21:32:14 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) |
() "Chris K. Jester-Young" <address@hidden>
() 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 ...........
pgpEjuH9GhG4v.pgp
Description: PGP signature