unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Ryan Culpepper <ryan-sDh8Nw2yj/+Vc3sceRu5cw@public.gmane.org>
To: Eli Barzilay <eli-oSK4jVRJLyZg9hUCZPvPmw@public.gmane.org>
Cc: "dev-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org"
	<dev-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org>,
	"Ludovic Courtès" <ludo-mXXj517/zsQ@public.gmane.org>,
	guile-devel-mXXj517/zsQ@public.gmane.org
Subject: Re: Enhancement to the syntax system?
Date: Tue, 10 Jul 2012 11:44:51 -0400	[thread overview]
Message-ID: <4FFC4DF3.8030203@cs.utah.edu> (raw)
In-Reply-To: <20476.16781.257276.194149-a5nvgYPMCZcx/1z6v04GWfZ8FUJU4vz8@public.gmane.org>

On 07/10/2012 10:51 AM, Eli Barzilay wrote:
> 20 minutes ago, Marijn wrote:
>>
>> It seems to me that both these results cannot be correct
>> simultaneously, but I'll await the experts' opinion on that.
>
> This does look weird:
>
>    #lang racket
>    (define-for-syntax (f stx) #`(let ([x 1]) #,stx))
>    (define-syntax (m stx)
>      (with-syntax ([zz (f #'x)]) #`(let ([x 2]) zz)))
>    (m)
>
> evaluates to 1, but if I change the first two "stx" names into "x"
> *or* if I change the argument name for the macro to "x", then it
> returns 2.

The difference between

(define-for-syntax (f1 stx) #`(let ([x 1]) #,stx)

and

(define-for-syntax (f2 x) #`(let ([x 1]) #,x)

is that the 'x' in the template in the 'f2' is not bound-identifier=? to 
the 'x' that appears in the template of 'm', because it has a rename 
wrap due to the 'x' formal parameter of 'f2'. That is, 'f2' behaves 
essentially the same as

(define-for-syntax (f2* x*) #`(let ([x* 1]) #,x*)

A likely mistake is to think that the wrap generated by the 'x' in 'f2' 
doesn't count because it happens before we get around to the "real" 
macro expansion that you care about. But that's not the case (at least 
in Racket).

A good rule of thumb is to never use local variable names in your macro 
implementation (including compile-time auxiliary functions) that also 
appear in the macro's template (including etc).

A related error is the "identifier used out of context" error that you 
get from, eg,

(define-syntax (m stx)
   (let ([+ *])
     #'(+ 1 2)))
(m)  ;; => identifier used out of context in: +

The binding of '+' in the macro changes the meaning of the '+' in the 
template, even though the bindings exist at different phases. You could 
perhaps avoid this issue by changing the hygiene algorithm by adding a 
phase level to rename wraps and skipping different-phase rename wraps 
during resolution. I'm not sure if this is a good idea or if anyone has 
tried it.

Ryan
_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev


  parent reply	other threads:[~2012-07-10 15:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-30 15:22 Enhancement to the syntax system? Stefan Israelsson Tampe
2012-07-02 19:28 ` Ludovic Courtès
2012-07-02 20:43   ` Stefan Israelsson Tampe
2012-07-02 22:41     ` Ludovic Courtès
2012-07-03 14:37       ` Stefan Israelsson Tampe
2012-07-03 21:33         ` Ludovic Courtès
2012-07-03 21:52           ` Stefan Israelsson Tampe
2012-07-04  7:47             ` Marijn
2012-07-04  8:04               ` Stefan Israelsson Tampe
2012-07-09 15:52             ` Ludovic Courtès
2012-07-09 17:40               ` Stefan Israelsson Tampe
2012-07-10  8:24                 ` Ludovic Courtès
2012-07-10 13:35                   ` Stefan Israelsson Tampe
2012-07-10 14:34                     ` Marijn
2012-07-10 14:51                       ` [racket-dev] " Eli Barzilay
     [not found]                         ` <20476.16781.257276.194149-a5nvgYPMCZcx/1z6v04GWfZ8FUJU4vz8@public.gmane.org>
2012-07-10 15:03                           ` Matthew Flatt
2012-07-10 15:26                             ` [racket-dev] " Ludovic Courtès
2012-07-10 15:44                               ` Stefan Israelsson Tampe
2012-07-10 17:47                                 ` Stefan Israelsson Tampe
2012-07-10 16:48                             ` Eli Barzilay
2014-05-03 21:29                             ` Marijn Schouten (hkBst)
2012-07-10 15:44                           ` Ryan Culpepper [this message]
2012-07-10 15:22                     ` Ludovic Courtès
2012-07-10  7:36               ` Stefan Israelsson Tampe

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=4FFC4DF3.8030203@cs.utah.edu \
    --to=ryan-sdh8nw2yj/+vc3sceru5cw@public.gmane.org \
    --cc=dev-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org \
    --cc=eli-oSK4jVRJLyZg9hUCZPvPmw@public.gmane.org \
    --cc=guile-devel-mXXj517/zsQ@public.gmane.org \
    --cc=ludo-mXXj517/zsQ@public.gmane.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).