From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Chris K. Jester-Young" Newsgroups: gmane.lisp.guile.devel Subject: Re: regexp-split for Guile Date: Tue, 18 Sep 2012 15:59:15 -0400 Message-ID: <20120918195915.GE6315@yarrow> References: <20120917140133.GA6315@yarrow> <87lig830ox.fsf@zigzag.favinet> <20120917200603.GB6315@yarrow> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1347998365 12124 80.91.229.3 (18 Sep 2012 19:59:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Sep 2012 19:59:25 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Sep 18 21:59:29 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 1TE3xB-00064q-3c for guile-devel@m.gmane.org; Tue, 18 Sep 2012 21:59:29 +0200 Original-Received: from localhost ([::1]:40532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE3x7-00052k-0A for guile-devel@m.gmane.org; Tue, 18 Sep 2012 15:59:25 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE3x3-00050s-7h for guile-devel@gnu.org; Tue, 18 Sep 2012 15:59:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TE3x1-0002zX-DB for guile-devel@gnu.org; Tue, 18 Sep 2012 15:59:21 -0400 Original-Received: from mail-qc0-f169.google.com ([209.85.216.169]:44999) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE3x1-0002yu-7C for guile-devel@gnu.org; Tue, 18 Sep 2012 15:59:19 -0400 Original-Received: by qcsd16 with SMTP id d16so256536qcs.0 for ; Tue, 18 Sep 2012 12:59:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=Y+sGmUIM3jAdh63d7E/GuCk+J4iFnFw2L4F7bVVBrtE=; b=r7zR6Tr8KWmEAPf0aFlfnxzz3InMLn1jMCBWVaAHN+tCVVaXg510y84yywhlXzjE4i QYy6k773TXjn0hdi7iFfLJyU6XPfVv0GYkTkIA2ZnU5FVRuVx9dLes/fatGtXZt1SlzE gHSzwIpmy7roz5tGMBztCPPPqQm/bwrTDLKHEMqLHfek5KJ4nYD3gsfIGZZnF2V/lcTh +t+gRoJ513j3ltx9r5TKqcD6loZNnEFUVOF866OB8rd0cifWebsEt3EBTp023UrDm/o+ wsDKONMan4xX1kXGHzYxrAQjGmXV0GjDSrd3mHJkzz1vIHFhm+3c3kCY6i+5G5Hiu4dT nhQg== Original-Received: by 10.224.217.136 with SMTP id hm8mr1976875qab.81.1347998358658; Tue, 18 Sep 2012 12:59:18 -0700 (PDT) Original-Received: from yarrow (cpe-069-134-140-185.nc.res.rr.com. [69.134.140.185]) by mx.google.com with ESMTPS id e5sm1074155qao.11.2012.09.18.12.59.17 (version=SSLv3 cipher=OTHER); Tue, 18 Sep 2012 12:59:17 -0700 (PDT) Mail-Followup-To: guile-devel@gnu.org Content-Disposition: inline In-Reply-To: <20120917200603.GB6315@yarrow> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.216.169 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:14897 Archived-At: Here's a revised version, implementing Thien-Thi Nguyen's comments. I added line breaks for the "cons" and the bottom "if" (I feel that the top "if" is still simple enough to keep on the same line). Cheers, Chris. * * * (define (regexp-split-fold match prev) (if (zero? (match:end match)) prev (cons* (match:end match) (substring (match:string match) (car prev) (match:start match)) (cdr prev)))) (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-null? final) final))))