From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.devel Subject: Re: regex-case Date: Mon, 08 Feb 2016 08:04:55 -0800 Message-ID: References: <61E420AD-70B6-4DEA-A7DD-EB123E22EFD0@verizon.net> <87oabrgtrg.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_C319760B-389A-480C-A808-D34594ACC4AB" X-Trace: ger.gmane.org 1454947661 8146 80.91.229.3 (8 Feb 2016 16:07:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Feb 2016 16:07:41 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Feb 08 17:07:32 2016 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 1aSoLc-0002oj-Ik for guile-devel@m.gmane.org; Mon, 08 Feb 2016 17:07:32 +0100 Original-Received: from localhost ([::1]:46101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoLb-00086G-S8 for guile-devel@m.gmane.org; Mon, 08 Feb 2016 11:07:31 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoJw-00068h-R0 for guile-devel@gnu.org; Mon, 08 Feb 2016 11:05:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSoJs-0007w1-FB for guile-devel@gnu.org; Mon, 08 Feb 2016 11:05:48 -0500 Original-Received: from vms173021pub.verizon.net ([206.46.173.21]:59356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoJs-0007io-7Z for guile-devel@gnu.org; Mon, 08 Feb 2016 11:05:44 -0500 Original-Received: from vz-proxy-m004.mx.aol.com ([64.236.83.15]) by vms173021.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0O2800A46KO8M190@vms173021.mailsrvcs.net> for guile-devel@gnu.org; Mon, 08 Feb 2016 10:04:57 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=J+9Xl1TS c=1 sm=1 tr=0 a=NimJJ1rWho3RDXpqkQh0Zg==:117 a=jFJIQSaiL_oA:10 a=o1OHuDzbAAAA:8 a=pGLkceISAAAA:8 a=mDV3o1hIAAAA:8 a=NEyV58nLBaRUoThT6eEA:9 a=QEXdDO2ut3YA:10 a=wfEtzIzonfnPfqVFqmAA:9 a=X5ARN20JdxWY0UaJ:21 a=_W_S_7VecoQA:10 Original-Received: by 72.87.204.128 with SMTP id 240d6002; Mon, 08 Feb 2016 16:04:56 GMT In-reply-to: X-Mailer: Apple Mail (2.2104) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.46.173.21 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:18151 Archived-At: --Apple-Mail=_C319760B-389A-480C-A808-D34594ACC4AB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Matt Wette matthew.wette@verizon.net > On Feb 8, 2016, at 7:40 AM, Stefan Israelsson Tampe = wrote: > ---------- Forwarded message ---------- > From: Stefan Israelsson Tampe > > Date: Mon, Feb 8, 2016 at 4:31 PM > Subject: Re: regex-case > To: Ludovic Court=C3=A8s > >=20 >=20 > An interesting question is what can be done by ice-9/match To provide background to the guile-devel list my prototype = implementation for regex-case is as follows (w/ error messages suggested = by Ludo now included): ;; helper macro for regex-case ;; (rx-let m (v ...) exp ...) =3D> (let ((v (match:substring m 1)) ...) = exp ...) (define-syntax rx-let (lambda (x) (syntax-case x () ((_ m (v ...) exp ...) (with-syntax (((i ...) (let f ((n 1) (vl #'(v ...))) ; fold (v ...) to (1 = ...) (if (null? vl) '() (cons n (f (1+ n) (cdr = vl))))))) #'(let ((v (match:substring m i)) ...) exp ...)))))) (define-syntax regex-case (lambda (x) (syntax-case x (else) ((_ str ((pat v ...) exp ...) ...) (with-syntax (((id ...) (generate-temporaries #'(pat ...)))) #'(let ((id (make-regexp pat)) ...) (cond ((regexp-exec id str) =3D> (lambda (m) (rx-let m (v ...) exp ...))) ... (else (error "regex-case: no match")))))) ((_ str ((pat v ...) exp ...) ... (else else-exp ...)) (with-syntax (((id ...) (generate-temporaries #'(pat ...)))) #'(let ((id (make-regexp pat)) ...) (cond ((regexp-exec id str) =3D> (lambda (m) (rx-let m (v ...) exp ...))) ... (else else-exp ...)))))))) --Apple-Mail=_C319760B-389A-480C-A808-D34594ACC4AB Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8



On Feb 8, 2016, at 7:40 AM, Stefan Israelsson Tampe <stefan.itampe@gmail.com> wrote:
---------- Forwarded message ----------
From: Stefan Israelsson = Tampe <stefan.itampe@gmail.com>
Date: = Mon, Feb 8, 2016 at 4:31 PM
Subject: Re: regex-case
To: Ludovic Court=C3=A8s <ludo@gnu.org>


An interesting question is what = can be done by ice-9/match

To provide = background to the guile-devel list my prototype implementation for = regex-case is as follows (w/ error messages suggested by Ludo now = included):

;; helper macro for = regex-case
;; = (rx-let m (v ...) exp ...) =3D> (let ((v (match:substring m 1)) ...) = exp ...)
(define-syntax rx-let
  (lambda (x)
    (syntax-case x = ()
  =     ((_ m (v ...) exp ...)
       (with-syntax (((i = ...)
=       (let f ((n 1) (vl #'(v ...))) ; fold (v = ...) to (1 ...)
= (if (null? vl) '() (cons n (f (1+ n) (cdr = vl)))))))
=  #'(let ((v (match:substring m i)) ...) exp = ...))))))

(define-syntax regex-case
  (lambda (x)
    (syntax-case x = (else)
  =     ((_ str ((pat v ...) exp ...) ...)
      =  (with-syntax (((id ...) (generate-temporaries #'(pat = ...))))
=  #'(let ((id (make-regexp pat)) ...)
     = (cond
=       ((regexp-exec id str) = =3D>
=        (lambda (m) (rx-let m (v ...) exp = ...)))
=       ...
      (else = (error "regex-case: no match"))))))
      ((_ str ((pat v ...) exp = ...) ... (else else-exp ...))
       (with-syntax (((id = ...) (generate-temporaries #'(pat ...))))
 #'(let ((id (make-regexp = pat)) ...)
=      (cond
     =  ((regexp-exec id str) =3D>
       = (lambda (m) (rx-let m (v ...) exp ...)))
     =  ...
=      (else else-exp = ...))))))))

= --Apple-Mail=_C319760B-389A-480C-A808-D34594ACC4AB--