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

identifers from nested syntax-rules macro #296

Open
Tracked by #43
jcubic opened this issue Jan 31, 2024 · 1 comment
Open
Tracked by #43

identifers from nested syntax-rules macro #296

jcubic opened this issue Jan 31, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@jcubic
Copy link
Collaborator

jcubic commented Jan 31, 2024

This simple macro doesn't work:

(define-syntax foo
  (syntax-rules ()
    ((_ a)
     (cond ((zero? a) 'zero)
           (else 'other)))))

(print (foo 10))

It throws an error because else got renamed to #:else.

@jcubic jcubic added the bug Something isn't working label Jan 31, 2024
@jcubic jcubic added this to the 1.0 milestone Jan 31, 2024
@jcubic
Copy link
Collaborator Author

jcubic commented Jan 31, 2024

That one case was fixed, the cond/else does not work inside syntax-rules, but this is just a hack.

For now, I will just put it as a limitation of LIPS:

You can use symbols inside lisp macros that will be used in syntax-rules macros because symbols will be gensyms. As a workaround, you can use what cond is doing:

(and (symbol? x)
     (or (eq? x 'else)
         (eq? (--> (new lips.LString (x.literal)) (cmp "else")) 0)))

This could be abstracted into some small function. Not sure about the name gensym=? is once but I would expect both arguments to be gensyms.

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