importing a syntactic binding for level -1

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

importing a syntactic binding for level -1

Marco Maggi-2
Ciao,

  it is my understanding that, if I write a macro as follows:

(import (scheme)
        (chicken fixnum))
(import-for-syntax (scheme)
                   (only (chicken syntax)
                         er-macro-transformer))

(define-syntax spiffy
  (er-macro-transformer
    (lambda (input-form.stx rename compare)
      (define %fx+ (rename 'fx+))
      ---)))

the function RENAME will pick  "fx+" from the runtime environment (which
is level 0).

  I would like to write such macro as:

(import (scheme)
        (chicken fixnum))
(import-for-syntax (scheme)
                   (only (chicken syntax)
                         er-macro-transformer)
                   (only (my-lib)
                         doit))

(define-syntax spiffy
  (er-macro-transformer
    (lambda (input-form.stx rename compare)
      (define %fx+ (doit rename))
      ---)))

and in the library "(my-lib)" I have:

(define (doit rename)
  (rename 'fx+))

but for  this to work  cleanly: in "(my-lib)"  I should import  "fx+" at
level -1?  Is it right?

  This is possible with R6RS implementations.  How about CHICKEN?

TIA
--
Marco Maggi

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users
Reply | Threaded
Open this post in threaded view
|

Re: importing a syntactic binding for level -1

Peter Bex
On Sat, Jul 13, 2019 at 08:26:56AM +0200, Marco Maggi wrote:

>   I would like to write such macro as:
>
> (import (scheme)
>         (chicken fixnum))
> (import-for-syntax (scheme)
>                    (only (chicken syntax)
>                          er-macro-transformer)
>                    (only (my-lib)
>                          doit))
>
> (define-syntax spiffy
>   (er-macro-transformer
>     (lambda (input-form.stx rename compare)
>       (define %fx+ (doit rename))
>       ---)))
>
> and in the library "(my-lib)" I have:
>
> (define (doit rename)
>   (rename 'fx+))
>
> but for  this to work  cleanly: in "(my-lib)"  I should import  "fx+" at
> level -1?  Is it right?
Hi Marco,

This won't work.  "rename" is operating in the syntactic environment
of the transformer.  You can pass it as a procedure to some other module,
but that won't change its internal state.

>   This is possible with R6RS implementations.  How about CHICKEN?

That is very surprising to me.  It should not be possible.  You're
probably comparing apples and oranges (syntax-case works differently
from ER macros).

Cheers,
Peter

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: importing a syntactic binding for level -1

Marco Maggi-2
Peter Bex wrote:

> This won't work.  "rename" is operating in the syntactic environment
> of the transformer.  You can pass it as a procedure to some other module,
> but that won't change its internal state.

So, is RENAME closed upon  the environment in which ER-MACRO-TRANSFORMER
is called?  So I can do something like:

(module (for-expand)
    (the-transformer)
  (import (scheme)
          (chicken syntax))
  (define (the-transformer input-form.stx rename compare)
    (define %fx+ (rename 'fx+))
    ---)
  #| end of module |#)

(module (for-runtime)
    ()
  (import (scheme)
          (chicken syntax)
          (chicken fixnum))
  (import-for-syntax (scheme)
                     (for-expand))
  (define-syntax the-macro
    (er-macro-transformer the-transformer))
  #| end of module |#)

and  RENAME  will  cleanly  pick  FX+  from  the  environment  in  which
ER-MACRO-TRANSFORMER has been called?

  I'm  not  trying   to  inject  syntactic  bindings   in  the  original
environment, I just want to put as much as possible of a macro body into
a separate library to be imported "for syntax".
--
Marco Maggi

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users
Reply | Threaded
Open this post in threaded view
|

Re: importing a syntactic binding for level -1

Peter Bex
On Sat, Jul 13, 2019 at 02:12:48PM +0200, Marco Maggi wrote:
> Peter Bex wrote:
>
> > This won't work.  "rename" is operating in the syntactic environment
> > of the transformer.  You can pass it as a procedure to some other module,
> > but that won't change its internal state.
>
> So, is RENAME closed upon  the environment in which ER-MACRO-TRANSFORMER
> is called?  So I can do something like:

Yes, that's how it should work.

>   I'm  not  trying   to  inject  syntactic  bindings   in  the  original
> environment, I just want to put as much as possible of a macro body into
> a separate library to be imported "for syntax".

Personally, I find that confusing, because the module containing the
macro definition determines the available identifiers.  If you then move
the actual expansion code to another module, that doesn't give a clue as
to which identifiers are available in the expansion.

So for stylistic reasons I'd avoid that.  You can still move processing
code to another module, but I would pass the renamed identifiers to the
helper procedure, instead of the "rename" procedure itself.

Cheers,
Peter

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users

signature.asc (499 bytes) Download Attachment