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: syntax-local-value patch for discussion Date: Fri, 9 Dec 2011 12:49:33 +0100 Message-ID: References: <87ty5aafpy.fsf@Kagami.home> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0015174c3ccae86e4e04b3a76002 X-Trace: dough.gmane.org 1323431390 9630 80.91.229.12 (9 Dec 2011 11:49:50 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 9 Dec 2011 11:49:50 +0000 (UTC) Cc: guile-devel To: Ian Price Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Dec 09 12:49:42 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RYyxS-0007Yg-Lw for guile-devel@m.gmane.org; Fri, 09 Dec 2011 12:49:42 +0100 Original-Received: from localhost ([::1]:54642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYyxS-0004aC-9y for guile-devel@m.gmane.org; Fri, 09 Dec 2011 06:49:42 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:58212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYyxN-0004Zt-Rr for guile-devel@gnu.org; Fri, 09 Dec 2011 06:49:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYyxL-0008Qg-SL for guile-devel@gnu.org; Fri, 09 Dec 2011 06:49:37 -0500 Original-Received: from mail-ey0-f169.google.com ([209.85.215.169]:60530) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYyxL-0008QS-Ev for guile-devel@gnu.org; Fri, 09 Dec 2011 06:49:35 -0500 Original-Received: by eaah1 with SMTP id h1so1819315eaa.0 for ; Fri, 09 Dec 2011 03:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=fcJEmlEapmpAh3kS3z1qy+1ac/jNiuyeymIFdPganb8=; b=B2NCYch1H+tP14NrT/xunD1AYQg5ELBneY5nKQMsRFPdmtZ3gV/LLUt/KgZAw3QMKy GO8rGuNoMgaAP1mZZNz1JeE+VcuXbnQH9utY5iR1P+U2ixEB5/Ex2HpfWcZzl8MhgT0w EXnpIXkbw+jupz17/3hgIjtvdESYUY1Cn1fGU= Original-Received: by 10.213.3.81 with SMTP id 17mr1763209ebm.148.1323431373597; Fri, 09 Dec 2011 03:49:33 -0800 (PST) Original-Received: by 10.213.22.210 with HTTP; Fri, 9 Dec 2011 03:49:33 -0800 (PST) In-Reply-To: <87ty5aafpy.fsf@Kagami.home> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.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:13028 Archived-At: --0015174c3ccae86e4e04b3a76002 Content-Type: text/plain; charset=ISO-8859-1 Hi, On Thu, Dec 8, 2011 at 10:58 PM, Ian Price wrote: > Stefan Israelsson Tampe writes: > > > So I tried to get hold of the macro binding. So with the following patch > wich should be enogh > > for me to make progress porting rackets syntax parse to guile. > > > > Would be very glad if we could find a interface to expose this > information that is sane > > and rigid manner. So we should discuss this feature. > As it stands, I agree it is pretty simplistic, but I'm not sure what to > propose :) What is the intended use cases for this? A compile-time > values mechanism? > In syntax-parse they associate atribute data to an attribute variable that also is a macro. So later on when the symbol is used the compiler want to get hold of the attribute data. So there is a need to get hold on the lambda that is associated with the symbol and then lookup the data via a weak hash table. > > Anyway about the patch. > > I added a fluid that is setted with a closure that captures enough > syntax information > > so that we can lookup the macro value local or global. It basically uses > the same method > > as psyntax macroexpander. > The patch looks fine to me, although I admit I have little experience > with psyntax. > Ok, > > > > Now we can write, > > (define-syntax info > > (lambda (x) > > (syntax-case x () > > ((_ x) > > (pk (syntax-binding-info (syntax->datum #'x))) > > #'#f)))) > FWIW, I wouldn't expect to have to pass a raw datum to any procedure > with a syntax prefix. If we keep this procedure, I think the > syntax->datum should be hid, or the procedure renamed. > An idea is to change the name to symbol-local-data. Another idea is to return the lookup function directly (I think that this might be needed as well to make sure that the same symbol has the same interpretation in two contexts) So for this function we could use the name local-symbol-lookup-function and then builed any secondary interfaces on that inside a proper module. > > So with this I can attach meta information to macros local or not by > > using a weak hash. > I have 'define-type' & 'type-case' macros, basically copied from > racket's plai language[0][1] , that suffers from a complete lack of > error handling in the case where the type-id is not, in fact, a > type-id. If I were to use this mechanism, I would create a weak hash of > datatype-ids, adding them to the hash with 'define-type', and checking > if they are in the hash in my 'type-case' macro. Would that be right? > Yes you can use this mechanism to do what you wan't. There might be better ways though. Anyway 1. In a separate module make the type-id:s and let them be macros with the lambda put as a key in a weak key hash table 2. in using the type-id in the expansion of a type-case you can now lookup the symbol's context and deduce the macro binding, get the lambda and check if it is in the weak key hash table. and as you say be able to do the sanity check. Another method would be to have the type-id:s syntactic context is a module toplevel variable, and from the syntax object deduce if it is a toplevel variable and if so check if the id is in the hash table. Maybe there is tools alredy made that does this in a simple straightforward way? If you would define a type-id locally then the only way to later check for valid type-id is to do (let-syntax ((type-id (register-and-return (lambda (x) (error "this is a type-id not a syntactic element"))) the-code-that-uses-type-id ...) where you would use my suggestion. the machanism I propose > 0. http://docs.racket-lang.org/plai/plai-scheme.html > 1. I can post these if people want them > -- > Ian Price > > "Programming is like pinball. The reward for doing it well is > the opportunity to do it again" - from "The Wizardy Compiled" > Cool, these libraries can be useful, /Stefan --0015174c3ccae86e4e04b3a76002 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

On Thu, Dec 8, 2011 at 10:58 PM, Ian = Price <ia= nprice90@googlemail.com> wrote:
Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:

> So I tried to get hold of the macro binding. So with the following pat= ch wich should be enogh
> for me to make progress porting rackets syntax parse to guile.
>
> Would be very glad if we could find a interface to expose this informa= tion that is sane
> and rigid manner. So we should discuss this feature.
As it stands, I agree it is pretty simplistic, but I'm not sure w= hat to
propose :) What is the intended use cases for this? A compile-time
values mechanism?

In synta= x-parse they associate atribute data to an attribute variable that also is = a macro.
So later on when the symbol is used the compiler want to get ho= ld of the attribute data.
So there is a need to get hold on the lambda that is associated with the sy= mbol and then lookup
the data via a weak hash table.
=A0
> Anyway about the patch.
> I added a fluid that is setted with a closure that captures enough syn= tax information
> so that we can lookup the macro value local or global. It basically us= es the same method
> as psyntax macroexpander.
The patch looks fine to me, although I admit I have little experience=
with psyntax.

Ok,
=A0
>
> Now we can write,
> (define-syntax info
> =A0 (lambda (x)
> =A0=A0=A0 (syntax-case x ()
> =A0=A0=A0=A0=A0 ((_ x)
> =A0=A0=A0=A0=A0=A0=A0 (pk (syntax-binding-info (syntax->datum #'= ;x)))
> =A0=A0=A0=A0=A0=A0=A0 #'#f))))
FWIW, I wouldn't expect to have to pass a raw datum to any proced= ure
with a syntax prefix. If we keep this procedure, I think the
syntax->datum should be hid, or the procedure renamed.

An idea is to=A0 change the name to symbol-= local-data. Another idea is to return
the lookup function directly (I th= ink that this might be needed as well to make sure
that the same symbol has the same interpretation in two contexts)
So for= this function we could use the name=A0 local-symbol-lookup-function
and= then builed any secondary interfaces on that inside a proper module.
=A0
> So with this I can attach meta information to macros local or not by > using a weak hash.
I have 'define-type' & 'type-case' macros, basica= lly copied from
racket's plai language[0][1] , that suffers from a complete lack of
error handling in the case where the type-id is not, in fact, a
type-id. If I were to use this mechanism, I would create a weak hash of
datatype-ids, adding them to the hash with 'define-type', and check= ing
if they are in the hash in my 'type-case' macro. Would that be righ= t?

Yes you can use this mechanism to do what you w= an't. There might be better ways though.
Anyway
1. In a separate= module make the type-id:s and let them be macros with the lambda put as a = key
in a weak key hash table
2. in using the type-id in the expansion of a t= ype-case you can now lookup the symbol's context and deduce the=A0 macr= o binding, get the lambda and check if it is in the weak key hash table. an= d as you say be able to do the sanity check.

Another method would be to have the type-id:s syntactic context is a mo= dule toplevel variable,
and from the syntax object deduce if it is a to= plevel variable and if so check if the id is in the hash table.
Maybe th= ere is tools alredy made that does this in a simple straightforward way?
If you would define a type-id locally then the only way to later check = for valid type-id is to do
(let-syntax ((type-id (register-and-return (l= ambda (x) (error "this is a type-id not a syntactic element"))) =A0=A0=A0=A0 the-code-that-uses-type-id ...)
where you would use my sugg= estion.

the machanism I propose
0. http://docs.racket-lang.org/plai/plai-scheme.html
1. I can post these if people want them
--
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"= ;

Cool, these libraries can be useful,/Stefan
--0015174c3ccae86e4e04b3a76002--