From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: eval-when not giving me what I hoped for Date: Wed, 10 Feb 2016 20:28:10 -0800 Message-ID: <45FAD965-ED1F-434A-9A1E-A17E2ED8E04D@verizon.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_BA7D8BC4-B691-4E17-A819-ABB50A839029" X-Trace: ger.gmane.org 1455165039 10396 80.91.229.3 (11 Feb 2016 04:30:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Feb 2016 04:30:39 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Feb 11 05:30:30 2016 Return-path: Envelope-to: guile-user@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 1aTith-0002ig-Vs for guile-user@m.gmane.org; Thu, 11 Feb 2016 05:30:30 +0100 Original-Received: from localhost ([::1]:46087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTitg-000443-7Y for guile-user@m.gmane.org; Wed, 10 Feb 2016 23:30:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTisx-0003uk-MY for guile-user@gnu.org; Wed, 10 Feb 2016 23:30:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTirm-0006T5-0l for guile-user@gnu.org; Wed, 10 Feb 2016 23:29:43 -0500 Original-Received: from vms173025pub.verizon.net ([206.46.173.25]:63535) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTirl-0006Sr-K6 for guile-user@gnu.org; Wed, 10 Feb 2016 23:28:29 -0500 Original-Received: from vz-proxy-m003.mx.aol.com ([64.236.83.8]) by vms173025.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0O2D001XS8EZ4R90@vms173025.mailsrvcs.net> for guile-user@gnu.org; Wed, 10 Feb 2016 22:28:12 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=J+9Xl1TS c=1 sm=1 tr=0 a=Bcm0RCOkHTZ4We9DUxtllQ==:117 a=jFJIQSaiL_oA:10 a=cxlD-C-T5ks4t7EFPjMA:9 a=QEXdDO2ut3YA:10 a=QcyokUozmGxDYCei:21 a=_W_S_7VecoQA:10 Original-Received: by 72.87.204.128 with SMTP id 1e2110fe; Thu, 11 Feb 2016 04:28:12 GMT 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.25 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12388 Archived-At: --Apple-Mail=_BA7D8BC4-B691-4E17-A819-ABB50A839029 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I am trying to get a macro to expand at compile time using eval-when, = but it=E2=80=99s not giving me what I expect: (eval-when (expand) (make-regexp pat)) =E2=80=A6 gets expanded to: (if #f #f) I would like to see something like=20 # Any help would be appreciated. =E2=80=94 Matt I get the same (if #f #f) result whether I use (expand) or (compile). Below is=20 1) my macro (missing the helpers all-const-string? and rx-let) 2) the macro I use to compile to il-tree and then back to scheme=20 3) the demo code=20 4) the output from expand =3D=3D=3D my macro =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D (define-syntax regexp-case (lambda (x) (syntax-case x (else) ((_ str ((pat v ...) exp ...) ... (else else-exp ...)) (with-syntax (((id ...) (generate-temporaries #'(pat ...)))) (all-const-string? #'(pat ...)) #'(let ((id (eval-when (expand) (make-regexp pat))) ...) (cond ((regexp-exec id str) =3D> (lambda (m) (rx-let m (v ...) exp ...))) ... (else else-exp ...))))) ((_ str ((pat v ...) exp ...) ...) (with-syntax (((id ...) (generate-temporaries #'(pat ...)))) (all-const-string? #'(pat ...)) #'(let ((id (eval-when (expand) (make-regexp pat))) ...) (cond ((regexp-exec id str) =3D> (lambda (m) (rx-let m (v ...) exp ...))) ... (else (scm-error #f "regexp-case" "no match found: ~S" (list str) #f))))))))) =3D=3D=3D the expand macro =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D #:use-module (srfi srfi-11) #:use-module (system base compile) (define* (expand-form e #:key (opts '())) (let-values (((exp env) (decompile (compile e #:from 'scheme #:to 'tree-il #:env (current-module)) #:from 'tree-il #:to 'scheme #:opts opts))) exp)) (define-syntax-rule (expand _expression_) (expand-form '_expression_)) =3D=3D=3D orig test case =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (regexp-case str (("^([a-z]+)\\(([0-9]+)\\)$" v i) (list v i)) (("^([a-z]+)$" v) (list v "1"))) =3D=3D=3D output from expand =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (let ((t-768 (if #f #f)) (t-769 (if #f #f))) (let ((t (regexp-exec t-768 str))) (if t (let ((m t)) (let ((v (match:substring m 1)) (i (match:substring m 2))) (list v i))) (let ((t (regexp-exec t-769 str))) (if t (let* ((m t) (v (match:substring m 1))) (list v "1")) (scm-error #f "regexp-case" "no match found: ~S" (list str) #f)))))) --Apple-Mail=_BA7D8BC4-B691-4E17-A819-ABB50A839029 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 I am trying to get a = macro to expand at compile time using eval-when, but it=E2=80=99s not = giving me what I expect:

(eval-when (expand) (make-regexp = pat)) =E2=80=A6

gets expanded to:

        (if #f #f)

I would like to see something like 

= #<regexp = 1098a2d40>

Any help = would be appreciated. =E2=80=94 Matt

I get the same (if #f = #f) result whether I use (expand) or (compile).

Below is 
1) my macro (missing the helpers = all-const-string? and rx-let)
2) the macro I use to compile to il-tree = and then back to scheme 
3) the demo = code 
4) the output from expand

=3D=3D=3D my macro = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D
(define-syntax regexp-case
  (lambda = (x)
    (syntax-case x (else)
      = ((_ str ((pat v ...) exp ...) ... (else else-exp ...))
      =  (with-syntax (((id ...) (generate-temporaries #'(pat = ...))))
= (all-const-string? #'(pat ...))
#'(let ((id (eval-when (expand) = (make-regexp pat))) ...)
=     (cond
    =  ((regexp-exec id str) =3D>
      (lambda (m) = (rx-let m (v ...) exp ...)))
    =  ...
=      (else else-exp ...)))))
      = ((_ str ((pat v ...) exp ...) ...)
       (with-syntax = (((id ...) (generate-temporaries #'(pat ...))))
= (all-const-string? #'(pat ...))
#'(let ((id (eval-when (expand) = (make-regexp pat))) ...)
=     (cond
    =  ((regexp-exec id str) =3D>
      (lambda (m) = (rx-let m (v ...) exp ...)))
    =  ...
=      (else
      (scm-error = #f "regexp-case"
=  "no match found: ~S" (list str)
=  #f)))))))))

=3D=3D=3D the expand = macro =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

#:use-module (srfi = srfi-11)

#:use-module (system base = compile)


(define* (expand-form e #:key (opts = '()))

  (let-values (((exp env) = (decompile

           =                 (compile e = #:from 'scheme

          =                     =       #:to 'tree-il

          =                     =       #:env (current-module))

           =                 #:from = 'tree-il

           =                 #:to = 'scheme

           =                 #:opts = opts)))

    exp))


(define-syntax-rule (expand = _expression_)

  (expand-form = '_expression_))


=3D=3D=3D orig test case = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
  = (regexp-case str
    (("^([a-z]+)\\(([0-9]+)\\)$" v = i)
     (list v i))
    = (("^([a-z]+)$" v)
     (list v "1")))

=3D=3D=3D output from expand =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D

(let = ((t-768 (if #f #f))

      = (t-769 (if #f #f)))

  (let ((t (regexp-exec t-768 = str)))

    (if t

      (let ((m = t))

        (let ((v = (match:substring m 1))

          =     (i (match:substring m 2)))

          (list = v i)))

      (let ((t = (regexp-exec t-769 str)))

        (if = t

          (let* = ((m t) (v (match:substring m 1)))

          =   (list v "1"))

          = (scm-error

          =   #f

          =   "regexp-case"

          =   "no match found: ~S"

          =   (list str)

          =   #f))))))


= --Apple-Mail=_BA7D8BC4-B691-4E17-A819-ABB50A839029--