From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Re: Enhancement to the syntax system? Date: Tue, 10 Jul 2012 09:36:19 +0200 Message-ID: References: <877gumufmq.fsf@gnu.org> <87r4stss4d.fsf@gnu.org> <878vf0o7gs.fsf@gnu.org> <87pq85dj8o.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=f46d044787555713d504c474c952 X-Trace: dough.gmane.org 1341905798 7992 80.91.229.3 (10 Jul 2012 07:36:38 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 10 Jul 2012 07:36:38 +0000 (UTC) Cc: guile-devel@gnu.org To: =?ISO-8859-1?Q?Ludovic_Court=E8s?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jul 10 09:36:38 2012 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 1SoUzp-0007us-LL for guile-devel@m.gmane.org; Tue, 10 Jul 2012 09:36:33 +0200 Original-Received: from localhost ([::1]:54061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoUzo-0006tx-Kf for guile-devel@m.gmane.org; Tue, 10 Jul 2012 03:36:32 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoUzk-0006tr-AP for guile-devel@gnu.org; Tue, 10 Jul 2012 03:36:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoUze-0003yz-Pb for guile-devel@gnu.org; Tue, 10 Jul 2012 03:36:27 -0400 Original-Received: from mail-yx0-f169.google.com ([209.85.213.169]:48477) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoUze-0003yl-HR; Tue, 10 Jul 2012 03:36:22 -0400 Original-Received: by yenr5 with SMTP id r5so12631141yen.0 for ; Tue, 10 Jul 2012 00:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Gj5jXk0oirldfUYG8JKrWzprbGWaCkkC7CSjA8hSgNM=; b=AKVmgmd7Xtv0+gT64ch32YooOxEmX3s7Hj3NnUkBJN9jU9Ow9SdWUkS+3COq8bheSs snNqkbNBwqQEPKppX02wKkQNurRdC7l0lvSD/cpWWzRnxM1wCEXu7ogSV5ET8I7zQIgf pFeX55yEWYfnh3k+QGs9Pt4lpv5OPw2BKMg8/JBGhal8+dLVB5mV+x5woriSVjTQSNC3 V5L/ZyLasbV11paBLiTF2hoPsNS2xi0foXnP1b2W/DVlwmpKdnqHjpQfuv8TuCSSEjra bRcdANH/sy7a7z9Sss/lSl+82Hj+YU09MnFH9zs7SF/drDW/8SQFX4Smj02dd0kkDibA JOwA== Original-Received: by 10.50.237.72 with SMTP id va8mr10371118igc.17.1341905780019; Tue, 10 Jul 2012 00:36:20 -0700 (PDT) Original-Received: by 10.50.41.196 with HTTP; Tue, 10 Jul 2012 00:36:19 -0700 (PDT) In-Reply-To: <87pq85dj8o.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.169 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:14723 Archived-At: --f46d044787555713d504c474c952 Content-Type: multipart/alternative; boundary=f46d044787555713c804c474c950 --f46d044787555713c804c474c950 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Ok, I coded a suggested syntax that is a quick solution but maybe not ideal because really this should be hanlded on the psyntax level. We probably cannot use the old syntax because it can break old code in other words one has to introduce new language elements. Also I asked on #scheme and tried to look into reference documentation for quasisyntax semantics. The answer I got on #scheme was that psyntax is buggy although I do not agree on that. I also felt that people is suspicious of my approach which is to write one macro and then dispatch to functions in stead of writing macro after macro. In all I don't think I am able to lift this idea to a larger community. So I sat down and implemented a simple algorithm see attachement. with this I can write, scheme@(guile-user)> (use-modules (syntax unquote++)) scheme@(guile-user)> (define (f x) #`(let ((x 1)) #,x)) scheme@(guile-user)> (define-syntax g (lambda (x) (syntax-case x () ((_ y) ##`(let ((x y)) #.((x) (f #'x))))))) scheme@(guile-user)> (g 4) $1 =3D 4 This will explicitly state what variables to transfer to the inserted expression. It's not ideal because I feel that the good way to handle this is to implicitly, which demands hacking psyntax, do this and simplify the syntax even more. also I cannot see how to implement #.@ but to hack psyntax. ##` also allow #, and #,@ which has the old meaning. Have fun /Stefan On Mon, Jul 9, 2012 at 5:52 PM, Ludovic Court=E8s wrote: > Hi! > > Stefan Israelsson Tampe skribis: > > > You do not need gensyms if you try to mimic or implement my suggested #= . > . > > On the > > other hand when if you do this > > > > (define (f stx) #`(let ((x 1)) #,stx)) > > > > and use this with > > > > #`(let ((x 2)) #,(f #'x)) > > OK, got it, thanks! > > (In case others wonder, the complete example is: > > (define (f stx) > #`(let ((x 1)) #,stx)) > (define-syntax foo > (lambda (s) > (syntax-case s () > ((_) > #`(let ((x 2)) #,(f #'x)))))) > > (foo) > =3D> 1 > ) > > The situation can be diagnosed with: > > (define (f stx) > #`(let ((x 1)) > #,(if (bound-identifier=3D? stx #'x) (error) stx))) > > But it doesn=92t help. > > > (with-syntax ((x (datum->syntax stx (gensym "x")))) #`(let ((x 2)) #,(f > > #'x)))))) > > Often, you could use =91generate-temporaries=92, which is a bit nicer. > > > Hope that this makes things clear! > > It does, thanks! > > It=92s true that it=92s annoying that the wrong binding is silently used. > Do you think it=92s common enough to justify new syntax? > > Thanks, > Ludo=92. > > > --f46d044787555713c804c474c950 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Ok, I coded a suggested syntax that is a quick solution but maybe not ideal= because really this should be hanlded on the psyntax level. We probably ca= nnot use the old syntax because it can break old code in other words one ha= s to introduce new language elements. Also I asked on #scheme and tried to = look into reference documentation for quasisyntax semantics. The answer I g= ot on #scheme was that psyntax is buggy although I do not agree on that. I = also felt that people is suspicious of my approach which is to write one ma= cro and then dispatch to functions in stead of writing macro after macro. I= n all I don't think I am able to lift this idea to a larger community.<= br>
So I sat down and implemented a simple algorithm see attachement. with = this I can write,

scheme@(guile-user)> (use-modules (syntax unquo= te++))
scheme@(guile-user)>
(define (f x)
=A0 #`(let ((x 1)) = #,x))

scheme@(guile-user)>
(define-syntax g
=A0 (lambda (x)
= =A0=A0=A0 (syntax-case x ()
=A0=A0=A0=A0=A0 ((_ y)
=A0=A0=A0=A0=A0= =A0=A0 ##`(let ((x y))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 #.((x) (f #= 9;x)))))))

scheme@(guile-user)> (g 4)
$1 =3D 4

This will explicitly state what variables to transfer to the inserted e= xpression. It's not ideal because I
feel that the good way to handl= e this is to implicitly, which demands hacking psyntax, do this and simplif= y the syntax even more. also I cannot see how to implement #.@ but to hack = psyntax.

##` also allow #, and #,@ which has the old meaning.

Have fun/Stefan

On Mon, Jul 9, 2012 at 5:52 PM, = Ludovic Court=E8s <ludo@gnu.org> wrote:
Hi!

Stefan Israelsson Tampe <stef= an.itampe@gmail.com> skribis:

> You do not need gensyms if you try to mimic or= implement my suggested #. .
> On the
> other hand when if you do this
>
> (define (f stx) #`(let ((x 1)) #,stx))
>
> and use this with
>
> #`(let ((x 2)) #,(f #'x))

OK, got it, thanks!

(In case others wonder, the complete example is:

=A0 (define (f stx)
=A0 =A0 #`(let ((x 1)) #,stx))
=A0 (define-syntax foo
=A0 =A0 (lambda (s)
=A0 =A0 =A0 (syntax-case s ()
=A0 =A0 =A0 =A0 ((_)
=A0 =A0 =A0 =A0 =A0#`(let ((x 2)) #,(f #'x))))))

=A0 (foo)
=A0 =3D> 1
)

The situation can be diagnosed with:

=A0 (define (f stx)
=A0 =A0 #`(let ((x 1))
=A0 =A0 =A0 #,(if (bound-identifier=3D? stx #'x) (error) stx)))
But it doesn=92t help.

> (with-syntax ((x (datum->syntax stx (gensym "x")))) #`(le= t ((x 2)) #,(f
> #'x))))))

Often, you could use =91generate-temporaries=92, which is a bit nicer= .

> Hope that this makes things clear!

It does, thanks!

It=92s true that it=92s annoying that the wrong binding is silently used. Do you think it=92s common enough to justify new syntax?

Thanks,
Ludo=92.



--f46d044787555713c804c474c950-- --f46d044787555713d504c474c952 Content-Type: application/octet-stream; name="unquote++.scm" Content-Disposition: attachment; filename="unquote++.scm" Content-Transfer-Encoding: base64 X-Attachment-Id: f_h4go49ub0 KGRlZmluZS1tb2R1bGUgKHN5bnRheCB1bnF1b3RlKyspCiAgIzpleHBvcnQgKHF1YXNpc3ludGF4 KysgaW5zeW50YXgpKQoKKGRlZmluZSAqcyogKG1ha2UtZmx1aWQgJygpKSkKCihkZWZpbmUgKHBh cnNlIHN0eCB4KQogIChzeW50YXgtY2FzZSB4ICh1bnN5bnRheCBpbnN5bnRheCB1bnN5bnRheC1z cGxpY2luZykKICAgICgodW5zeW50YXggICAgICAgICAgLiBfKSB4KQogICAgKCh1bnN5bnRheC1z cGxpY2luZyAuIF8pIHgpCiAgICAoKGluc3ludGF4ICgocCAuLi4pIGMgLi4uKSkKICAgICAod2l0 aC1zeW50YXggKChnIChkYXR1bS0+c3ludGF4IHN0eCAoZ2Vuc3ltICJnIikpKSkKICAgICAgIChm bHVpZC1zZXQhICpzKiAoY29ucyAjJyhnIChsYW1iZGEgKHgpIAogICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAoc3ludGF4LWNhc2UgeCAoKSAKICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAoKF8gcCAuLi4pIChiZWdpbiBjIC4uLikpKSkpCiAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgKGZsdWlkLXJlZiAqcyopKSkKICAgICAgICMnKGcgcCAuLi4pKSkK ICAgICgoeCAuIGwpCiAgICAgKGNvbnMgKHBhcnNlIHN0eCAjJ3gpIChwYXJzZSBzdHggIydsKSkp CiAgICAoeCAjJ3gpKSkKCihkZWZpbmUtc3ludGF4IHF1YXNpc3ludGF4KysKICAobGFtYmRhICh4 KQogICAgKHN5bnRheC1jYXNlIHggKCkKICAgICAgKChfIHkpCiAgICAgICAoYmVnaW4KICAgICAg ICAgKGZsdWlkLXNldCEgKnMqICcoKSkKICAgICAgICAgKHdpdGgtc3ludGF4ICgoc3RhdGVtZW50 IChwYXJzZSB4ICMneSkpCiAgICAgICAgICAgICAgICAgICAgICAgKGxldHMgICAgICAoZmx1aWQt cmVmICpzKikpKQogICAgICAgICAgICMnKHF1YXNpc3ludGF4IChsZXQtc3ludGF4IGxldHMgc3Rh dGVtZW50KSkpKSkpKSkKICAgICAgICAgICAgICAgCihkZWZpbmUgKHJnIGNoIHN0cmVhbSkKICAo bGV0ICgoeCAocmVhZC1jaGFyIHN0cmVhbSkpKQogICAgKGNvbmQKICAgICAoKGVxdj8geCAjXGAp CiAgICAgIGAocXVhc2lzeW50YXgrKyAsKHJlYWQgc3RyZWFtKSkpCiAgICAgKCN0CiAgICAgIChl cnJvciAiV3JvbmcgZm9ybWF0IG9mICMgcmVhZGVyIGV4dGVuc2lvbiIpKSkpKQoKKGRlZmluZSAo cmcuIGNoIHN0cmVhbSkgYChpbnN5bnRheCAsKHJlYWQgc3RyZWFtKSkpCgoocmVhZC1oYXNoLWV4 dGVuZCAjXCMgcmcpCihyZWFkLWhhc2gtZXh0ZW5kICNcLiByZy4pCg== --f46d044787555713d504c474c952--