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

Different calls to hygienic macros should create unique hygiene values #288

Closed
Tracked by #43
jcubic opened this issue Jan 23, 2024 · 0 comments
Closed
Tracked by #43
Labels
bug Something isn't working
Milestone

Comments

@jcubic
Copy link
Owner

jcubic commented Jan 23, 2024

This code from SRFI-210 doesn't work correctly:

(define-syntax call/mv
  (syntax-rules ()
    ((call/mv consumer producer1 ...)
     (letrec-syntax
         ((aux (syntax-rules ::: ()
                 ((aux %consumer () ((%producer1 args1) :::))
                  (let-values (((proc) %consumer)
                               (args1 %producer1) :::)
                    (apply proc (append args1 :::))))
                 ((aux %consumer (%producer1 producer2 :::) (temp :::))
                  (aux %consumer (producer2 :::) (temp ::: (%producer1 args1)))))))
       (aux consumer (producer1 ...) ())))))


(print (call/mv string (values #\a #\b) (values #\c #\d)))
;; ==> cdcd

It should print abcd the same as Gauche, all different implementations fail to run this code.

The problem is that this is a recursive deep first expansion and each expansion should create new unique value of args1 that is a free variable in this pattern. But because syntax-rules just collect the name and use them inside the macro they are the same. And last value is used.

It's because this also works:

(let-values ((x (values 1 2 3))
             (x (values 4 5 6)))
  (display x)
  (newline))
;; ==> (4 5 6)

the same value in let-values works and x shadow previous x.

@jcubic jcubic added the bug Something isn't working label Jan 23, 2024
@jcubic jcubic changed the title Diffrent calls to hygienic macros should create unique hygien values Different calls to hygienic macros should create unique hygiene values Jan 23, 2024
jcubic added a commit that referenced this issue Jan 23, 2024
@jcubic jcubic closed this as completed Jan 25, 2024
@jcubic jcubic added this to the 1.0 milestone Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant