unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <mwette@alumni.caltech.edu>
To: guile-user@gnu.org
Subject: a Q on syntax-rules vs syntax-case
Date: Thu, 05 Feb 2015 11:44:13 -0800	[thread overview]
Message-ID: <E785699C-CF62-4780-A29F-E8EC97B7CFD4@alumni.caltech.edu> (raw)

I want to use macros inside a let which is part of an expansion of a top-level macro in order to have local bindings visible to macros. 

Is there a difference in implementation (e.g., when inside macros get expanded) between using syntax-rules versus syntax-case at the top level.   Is this coding considered OK?

(define-syntax foo
  (lambda (x)
    (syntax-case x ()
      ((_ <e>)
       #'(let* ((v (cons 'a #f))
		(doit (lambda (x) (set-cdr! v x))))
	   (letrec-syntax
	       ((foo-1 (syntax-rules ()
			 ((_ <v>)
			  (doit '<v>)))))
	     (foo-1 <e>))
	   v)))))

(define-syntax bar
  (syntax-rules ()
    ((_ <e>)
     (let* ((v (cons 'a #f))
	    (doit (lambda (x) (set-cdr! v x))))
       (letrec-syntax
	   ((foo-1 (syntax-rules ()
		     ((_ <v>)
		      (doit '<v>)))))
	 (foo-1 <e>))
       v))))

(foo 1) => (a . 1)
(bar 1) => (a . 1)




             reply	other threads:[~2015-02-05 19:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05 19:44 Matt Wette [this message]
2015-02-09  1:48 ` a Q on syntax-rules vs syntax-case Mark H Weaver
2015-02-09  2:36   ` Matt Wette

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=E785699C-CF62-4780-A29F-E8EC97B7CFD4@alumni.caltech.edu \
    --to=mwette@alumni.caltech.edu \
    --cc=guile-user@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).