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

macroexpand and nested syntax-rules #357

Open
jcubic opened this issue Mar 31, 2024 · 2 comments
Open

macroexpand and nested syntax-rules #357

jcubic opened this issue Mar 31, 2024 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@jcubic
Copy link
Collaborator

jcubic commented Mar 31, 2024

(define-syntax when
  (syntax-rules ()
    ((_ test body ...)
     (let ((tmp test))
        (if tmp
            (begin
              body ...))))))


(let ((alist '((foo . "lorem") (bar . "ipsum") (baz . "dolor")))
      (begin (lambda () 10)))
  (pprint (macroexpand (when (assoc 'bar alist) #void))))

;; ==> (#:let ((#:tmp (assoc (quote bar)
;; ==>                       alist)))
;; ==>       (#:if #:tmp
;; ==>            (#:begin
;; ==>              )
;; ==>            ))

(define-syntax-parameter it (syntax-rules () ((_) (syntax-error "Use outside aif"))))

(define-syntax awhen
  (syntax-rules ()
    ((_ test body ...)
     (let ((tmp test))
       (syntax-parameterize
        ((it (syntax-rules ()
               ((_) tmp))))
        (if tmp
            (begin
              body ...)))))))

(let ((alist '((foo . "lorem") (bar . "ipsum") (baz . "dolor")))
      (begin (lambda () 10)))
  (pprint (macroexpand (awhen (assoc 'bar alist) #void))))
;; ==> syntax-rules: no matching syntax in macro (awhen)
@jcubic jcubic added the bug Something isn't working label Mar 31, 2024
@jcubic jcubic added this to the 1.0 milestone Mar 31, 2024
@jcubic
Copy link
Collaborator Author

jcubic commented Mar 31, 2024

This is actually a collision of _ binding that is used in nested syntax-rules. It works as code but fail when expanding.

(define-syntax symbol
  (syntax-rules ()
    ((_ name)
     (let-syntax ((name (syntax-rules ()
                       ((_)
                        (list 'name)))))
       (name)))))

(print (symbol hello))
;; ==> (hello)
(pprint (macroexpand (symbol hello)))
;; ==> syntax-rules: no matching syntax in macro (symbol)

@jcubic jcubic changed the title You can't macroexpand macro that use syntax-parameterize Variable collision in nested syntax-rules when using macroexpand Mar 31, 2024
@jcubic
Copy link
Collaborator Author

jcubic commented Mar 31, 2024

It's not a collision only macroexpand try to evaluate (symbol) inside pattern of syntax-rules.

This is the problem that macroexpand know nothing about nested syntax-rules. That's why they don't expand at all.

@jcubic jcubic changed the title Variable collision in nested syntax-rules when using macroexpand macroexpand and nested syntax-rules Mar 31, 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