unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: guile-devel@gnu.org
Subject: Re: regexp-split for Guile
Date: Mon, 17 Sep 2012 21:32:14 +0200	[thread overview]
Message-ID: <87lig830ox.fsf@zigzag.favinet> (raw)
In-Reply-To: <20120917140133.GA6315@yarrow> (Chris K. Jester-Young's message of "Mon, 17 Sep 2012 10:01:33 -0400")

[-- Attachment #1: Type: text/plain, Size: 2072 bytes --]

() "Chris K. Jester-Young" <cky944@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 ...........


[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

  reply	other threads:[~2012-09-17 19:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-17 14:01 regexp-split for Guile Chris K. Jester-Young
2012-09-17 19:32 ` Thien-Thi Nguyen [this message]
2012-09-17 20:06   ` Chris K. Jester-Young
2012-09-18  7:06     ` Sjoerd van Leent Privé
2012-09-18 19:31       ` Chris K. Jester-Young
2012-09-18 19:59     ` Chris K. Jester-Young
2012-10-07  2:38       ` Daniel Hartwig
2012-10-12 21:57         ` Mark H Weaver
2012-10-20  4:01           ` Chris K. Jester-Young
2012-10-20 13:27             ` Mark H Weaver
2012-10-20 14:16               ` Mark H Weaver
2012-10-21  8:20                 ` Daniel Hartwig
2012-10-21 19:23                   ` Chris K. Jester-Young
2012-10-21 16:08                 ` Chris K. Jester-Young
2012-09-18 12:59 ` nalaginrut
2012-09-18 19:55   ` Chris K. Jester-Young
2012-09-19  0:30     ` nalaginrut
2012-10-04 21:47 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lig830ox.fsf@zigzag.favinet \
    --to=ttn@gnuvola.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).