Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support srfi-147 #1067

Open
shirok opened this issue Aug 14, 2024 · 1 comment
Open

Support srfi-147 #1067

shirok opened this issue Aug 14, 2024 · 1 comment

Comments

@shirok
Copy link
Owner

shirok commented Aug 14, 2024

Now we accept general expressions as transformer-spec, as far as it yields a macro transformer, so we've already come half way to support srfi-147.

https://srfi.schemers.org/srfi-147/srfi-147.html

It fails when <transformer spec> is a <macro use> that expands into (being <defintiion> ... <transformer spec>). (It words if we directly have (begin ...) form).

@shirok
Copy link
Owner Author

shirok commented Aug 16, 2024

Allowing arbitrary expressions, and especially the (begin <definition> ... <transformer-spec>) form, pose a difficult issue. It can create a lexical environment at runtime, that only to be inserted by the macro.

One of such case is exhibited by a test of srfi-147:

        (define-syntax my-macro-transformer
          (syntax-rules ()
            ((my-macro-transformer)
             (begin (define foo 2)
                    (syntax-rules ()
                      ((_) foo))))))

        (test-equal 42 (* 21 (letrec-syntax ((foo (my-macro-transformer)))
                               (foo)))))

(my-macro-transformer) expands into a (begin ...) form, which evaluates at compile-time to become a macro transformer. When that is expanded in the test-equal form, it inserts a variable reference to foo, which is the identifier introduced in the macro expansion. But currently, transformer-spec is evaluated solely in the compile-time environment, the binding of foo introduced in my-macro-transformer does not exist in the runtime environment.

The definition in the new (begin ..) form may close any runtime environment surrounding it, so we need to emit the binding form into the macro output somehow, and let the runtime evaluation takes care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant