From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ryan Culpepper Newsgroups: gmane.comp.lang.racket.devel,gmane.lisp.guile.devel Subject: Re: Enhancement to the syntax system? Date: Tue, 10 Jul 2012 11:44:51 -0400 Message-ID: <4FFC4DF3.8030203@cs.utah.edu> References: <877gumufmq.fsf@gnu.org> <87r4stss4d.fsf@gnu.org> <878vf0o7gs.fsf@gnu.org> <87pq85dj8o.fsf@gnu.org> <87sjd058ia.fsf@gnu.org> <4FFC3D72.8070506@gentoo.org> <20476.16781.257276.194149@winooski.ccs.neu.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1341935133 21348 80.91.229.3 (10 Jul 2012 15:45:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 10 Jul 2012 15:45:33 +0000 (UTC) Cc: "dev-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org" , =?ISO-8859-1?Q?Ludovic_Court=E8s?= , guile-devel-mXXj517/zsQ@public.gmane.org To: Eli Barzilay Original-X-From: dev-bounces-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org Tue Jul 10 17:45:28 2012 Return-path: Envelope-to: gclrd-dev-1dZseelyfdZg9hUCZPvPmw@public.gmane.org Original-Received: from champlain.ccs.neu.edu ([129.10.115.116]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Soccv-0003NK-AR for gclrd-dev-1dZseelyfdZg9hUCZPvPmw@public.gmane.org; Tue, 10 Jul 2012 17:45:25 +0200 Original-Received: from champlain.ccs.neu.edu (localhost.localdomain [127.0.0.1]) by champlain.ccs.neu.edu (8.14.4/8.14.4) with ESMTP id q6AFj2J4022283; Tue, 10 Jul 2012 11:45:02 -0400 Original-Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com [74.125.82.42]) by champlain.ccs.neu.edu (8.14.4/8.14.4) with ESMTP id q6AFiuJZ022266 for ; Tue, 10 Jul 2012 11:44:57 -0400 Original-Received: by wgbds11 with SMTP id ds11so3575219wgb.3 for ; Tue, 10 Jul 2012 08:44:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-virus-scanned:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding:x-gm-message-state; bh=3OYTtnKcx2DUEZd4pS3xnKcAimltszTZd5cEnUl2SWY=; b=KZ9lbraQxjGFRAxfWAwJnbmzC9AEhVk7fD1kvPKT4YfKyMX/E6JQqOyt40JAoIWY0X J1NUB405wj4lbw/NrQuYkEF7JuRczqAGX/cpACEcOi1V9MdUVSJ8pwR2H3+Q08TynexN tYteEJ1QxbxKZYopYGG2jmo14ExsUWw9U6MyxTNRGdN36Oyh+b4uU2ndRYf9VBmHahvS NrCha2OC6IRnUuX4fPH9XC2txjUjpNCohe2yNqiOA8hDdbPwU3d7sdzEyJhRSqrbKhWf B0XdNG4Y2LN/k9oP0x/7ZrFhc903/zhQoKw0sOEALKkezWkN/7pPW116hVUlCgb5Q9zX 2Gug== Original-Received: by 10.216.212.217 with SMTP id y67mr18827132weo.173.1341935096346; Tue, 10 Jul 2012 08:44:56 -0700 (PDT) X-Forwarded-To: dev-ETbvJ2rUIr5TJLIrbSsYWiH1kwoRJHTR@public.gmane.org X-Forwarded-For: dev-PQOLPrHdAZ4YeIxN5WHPnw@public.gmane.org dev-ETbvJ2rUIr5TJLIrbSsYWiH1kwoRJHTR@public.gmane.org Original-Received: by 10.194.56.229 with SMTP id d5csp251199wjq; Tue, 10 Jul 2012 08:44:55 -0700 (PDT) Original-Received: by 10.68.217.166 with SMTP id oz6mr70045370pbc.136.1341935094837; Tue, 10 Jul 2012 08:44:54 -0700 (PDT) Original-Received: from mail-svr1.cs.utah.edu (mail-svr1.cs.utah.edu. [155.98.64.241]) by mx.google.com with ESMTP id od10si14695250pbb.321.2012.07.10.08.44.54; Tue, 10 Jul 2012 08:44:54 -0700 (PDT) Received-SPF: pass (google.com: domain of ryan-sDh8Nw2yj/+Vc3sceRu5cw@public.gmane.org designates 155.98.64.241 as permitted sender) client-ip=155.98.64.241; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ryan-sDh8Nw2yj/+Vc3sceRu5cw@public.gmane.org designates 155.98.64.241 as permitted sender) smtp.mail=ryan-sDh8Nw2yj/+Vc3sceRu5cw@public.gmane.org Original-Received: from localhost (localhost [127.0.0.1]) by mail-svr1.cs.utah.edu (Postfix) with ESMTP id 0FF1C6500EE; Tue, 10 Jul 2012 09:44:54 -0600 (MDT) X-Virus-Scanned: amavisd-new at cs.utah.edu Original-Received: from mail-svr1.cs.utah.edu ([127.0.0.1]) by localhost (mail-svr1.cs.utah.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6h1HrHMDnaIa; Tue, 10 Jul 2012 09:44:53 -0600 (MDT) Original-Received: from [192.168.20.176] (nomad.ccs.neu.edu [129.10.110.45]) by smtps.cs.utah.edu (Postfix) with ESMTPSA id D78E76500D9; Tue, 10 Jul 2012 09:44:52 -0600 (MDT) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 In-Reply-To: <20476.16781.257276.194149-a5nvgYPMCZcx/1z6v04GWfZ8FUJU4vz8@public.gmane.org> X-Gm-Message-State: ALoCoQmGL6UpwEYH3JIasMGZBjEu/Fw892N7jnD/y5+5DCNunJ/d1eU9OpFZvefHa3Nz38nL8gZW X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on champlain.ccs.neu.edu X-BeenThere: dev-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Racket Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: dev-bounces-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org Errors-To: dev-bounces-GvBox1K3Ixw1Q5oZIJT9Xw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.racket.devel:6401 gmane.lisp.guile.devel:14733 Archived-At: 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