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

You can't define class inside syntax-rules macro #124

Open
Tracked by #43
jcubic opened this issue Feb 13, 2021 · 1 comment
Open
Tracked by #43

You can't define class inside syntax-rules macro #124

jcubic opened this issue Feb 13, 2021 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@jcubic
Copy link
Collaborator

jcubic commented Feb 13, 2021

I've tried to create syntax-rules macro for definition of records:

(define-syntax define-record-type
  (syntax-rules ()
    ((_ "field" arg get set)
     (begin
       (define (get obj)
         (. obj 'arg))
       (define (set obj value)
         (set-obj! obj 'arg value))))
    ((_ name (constructor-name arg ...) pred (var get set) ...)
     (begin
       (define tmp (class Object
                     (constructor (lambda (self arg ...)
                                    (begin
                                      (set-obj! self 'arg arg)
                                      ...)))
                     (toString (lambda (self) 
                                 (symbol->string name)))))
        (define (constructor-name arg ...)
          (new tmp arg ...))
        (define (pred obj)
           (instanceof tmp obj))
        (begin (define-record-type "field" var get set)
               ...)))))

The problem is that constructor is JS function and it got renamed, so another example of dumb symbol rename that failed. This will need to wait for refactor of syntax-rules and adding expantion time for proper handling of LIPS constructs that create new scope variables like let and in this case object methods.

@jcubic jcubic added the bug Something isn't working label Feb 13, 2021
@jcubic jcubic added this to the 1.1 milestone Mar 12, 2021
@jcubic
Copy link
Collaborator Author

jcubic commented Aug 14, 2021

The solution would be to have a deep first macro expander.

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