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

Error in macroexpand #9

Closed
jcubic opened this issue May 8, 2019 · 2 comments
Closed

Error in macroexpand #9

jcubic opened this issue May 8, 2019 · 2 comments
Labels
bug Something isn't working resolved

Comments

@jcubic
Copy link
Collaborator

jcubic commented May 8, 2019

With macro:

(define-macro (define-symbol-macro . rest)
  "(define-symbol-macro (name . args) . body)
   
   Macro that creates special symbol macro for evaluator similar to build in , or `.
   It's like alias for real macro. Similar to CL reader macros but it receive already
   parsed code like normal macros."
   ;; this is executed in two different ways one when there are no macro and the other
   ;; if there is macro defined, in second case it will put list as first element
   ;; of the body even is it's called like this (define-symbol-macro (# code) 
   (let* ((def (if (pair? (car rest)) (caar rest) (car rest)))
          (symbol (car def))
          (code (cdr rest)))
     `(begin (add-special! ',symbol) (define-macro ,def ,@code))))

code:

 (macroexpand (define-symbol-macro (# arg) `(list->array (list ,@arg))))

output:

(begin
  (add-special! (quote list->array (quote )))
  (define-macro (list->array (quote list))
    (quasiquote (list->array (quote (unquote list))))
    ))
@jcubic jcubic added the bug Something isn't working label May 8, 2019
@jcubic jcubic added the resolved label May 8, 2019
@jcubic
Copy link
Collaborator Author

jcubic commented May 8, 2019

Current result:

lips> (macroexpand (define-symbol-macro (# arg) `(list->array (list ,@arg))))
(let* ((def (if (pair? (car rest))
                (caar rest)
                (car rest)))
       (symbol (car def)) (code (cdr rest)))
  (quasiquote (begin
                (add-special! (quote (unquote symbol)))
                (define-macro (unquote def)
                  (unquote-splicing code)
                  ))))

@jcubic
Copy link
Collaborator Author

jcubic commented May 8, 2019

There is also fix in formatter the updated code look like this:

(let* ((def (if (pair? (car rest))
                (caar rest)
                (car rest)))
       (symbol (car def)) (code (cdr rest)))
  (quasiquote (begin
                (add-special! (quote (unquote symbol)))
                (define-macro (unquote def)
                  (unquote-splicing code)))))

@jcubic jcubic closed this as completed May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

No branches or pull requests

1 participant