From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.lisp.guile.devel Subject: Re: regexp-split for Guile Date: Mon, 17 Sep 2012 21:32:14 +0200 Message-ID: <87lig830ox.fsf@zigzag.favinet> References: <20120917140133.GA6315@yarrow> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1347910356 2170 80.91.229.3 (17 Sep 2012 19:32:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 17 Sep 2012 19:32:36 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Sep 17 21:32:40 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TDh3d-0005YO-4Q for guile-devel@m.gmane.org; Mon, 17 Sep 2012 21:32:37 +0200 Original-Received: from localhost ([::1]:45557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDh3Y-00089X-Sh for guile-devel@m.gmane.org; Mon, 17 Sep 2012 15:32:32 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDh3V-00089C-D3 for guile-devel@gnu.org; Mon, 17 Sep 2012 15:32:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TDh3U-0000Z6-B1 for guile-devel@gnu.org; Mon, 17 Sep 2012 15:32:29 -0400 Original-Received: from smtp209.alice.it ([82.57.200.105]:51874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDh3T-0000WC-Vo for guile-devel@gnu.org; Mon, 17 Sep 2012 15:32:28 -0400 Original-Received: from zigzag.favinet (188.10.73.198) by smtp209.alice.it (8.6.023.02) id 504696FF024A4DF5 for guile-devel@gnu.org; Mon, 17 Sep 2012 21:32:10 +0200 Original-Received: from ttn by zigzag.favinet with local (Exim 4.72) (envelope-from ) id 1TDh3T-0004Lw-5f for guile-devel@gnu.org; Mon, 17 Sep 2012 21:32:27 +0200 In-Reply-To: <20120917140133.GA6315@yarrow> (Chris K. Jester-Young's message of "Mon, 17 Sep 2012 10:01:33 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 82.57.200.105 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:14890 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable () "Chris K. Jester-Young" () Mon, 17 Sep 2012 10:01:33 -0400 (define (string-empty? str) (zero? (string-length str))) You can use =E2=80=98string-null?=E2=80=99 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 =E2=80=98if=E2=80=99 expressions w/ the= condition, then and else expressions on separate lines. Similarly =E2=80=98cons=E2=80= =99. 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 =E2=80=98regexp-spl= it=E2=80=99 is called w/ negative =E2=80=98limit=E2=80=99? Should that be handled in = =E2=80=98regexp-split=E2=80=99 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. =2D-=20 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 ........... --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAlBXesIACgkQZwMiJEyAdQKNwwCg0Fnq0SQGWJ9FcnWDDWS7iDUv dkIAmwdk4o03HuFmmVzGldcP4lhnrZRv =KMEE -----END PGP SIGNATURE----- --=-=-=--