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 defining macro-defining macro #56

Open
TheGreatCatAdorer opened this issue Apr 8, 2022 · 3 comments
Open

Error defining macro-defining macro #56

TheGreatCatAdorer opened this issue Apr 8, 2022 · 3 comments

Comments

@TheGreatCatAdorer
Copy link

(let w (gensym W) x (gensym X) y (gensym Y) zs (gensym Zs)
  (defmacro declare-reduce-binary
    [declare [reduce-binary Name] | Declarations] ->
      (let macro-name (gensym Name)
        [[lambda x [lambda y y]]
         [defmacro macro-name
           [query reduce-binary Name] -> macro-name
           [Name w x y | zs] -> [Name w [Name x y | zs]]]
         [declare | Declarations]])))

error: The function SHEN::V154 is undefined.
version:

Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, Shen 22.2
running under Common Lisp, implementation: SBCL
port 3.0.3 ported by Mark Tarver, Robert Koeninger and Bruno Deferrari
@TheGreatCatAdorer
Copy link
Author

Additionally, any further entries into the REPL error with The function SHEN::|declare-reduce-binary| is undefined.

@TheGreatCatAdorer
Copy link
Author

TheGreatCatAdorer commented Apr 8, 2022

Reads as

[LET* [[w [gensym [QUOTE W]]]
       [x [gensym [QUOTE X]]]
       [y [gensym [QUOTE Y]]]
       [zs [gensym [QUOTE Zs]]]]
  [defun [QUOTE declare-reduce-binary] [V20]
    [COND [[AND [CONSP [QUOTE V20]]
                [AND [EQ [CAR [QUOTE V20]] [QUOTE declare]]
                [AND [CONSP [CDR [QUOTE V20]]]
                [AND [CONSP [CAR [CDR [QUOTE V20]]]]
                [AND [EQ [CAR [CAR [CDR [QUOTE V20]]]] [QUOTE reduce-binary]]
                [AND [CONSP [CDR [CAR [CDR [QUOTE V20]]]]]
                     [NULL [CDR [CDR [CAR [CDR [QUOTE V20]]]]]]]]]]]]
             [LET [[macro-name [gensym [CAR [CDR [CAR [CDR [QUOTE V20]]]]]]]]
               [LIST [LIST [QUOTE lambda] x [LIST [QUOTE lambda] y y]]
                     [LIST [QUOTE defmacro] macro-name
                           [CONS [QUOTE query] [CAR [CDR [QUOTE V20]]]]
                           [QUOTE ->]
                           macro-name 
                           [CONS [CAR [CDR [CAR [CDR [QUOTE V20]]]]]
                                 [CONS w [CONS x [CONS y zs]]]]
                           [QUOTE ->]
                           [LIST [CAR [CDR [CAR [CDR [QUOTE V20]]]]]
                                 w
                                 [CONS [CAR [CDR [CAR [CDR [QUOTE V20]]]]]
                                       [CONS x [CONS y zs]]]]]
                     [CONS [QUOTE declare]
                           [CDR [CDR [QUOTE V20]]]]]]]
          [T [QUOTE V20]]]]]

@tizoc
Copy link
Member

tizoc commented Apr 8, 2022

Hi @TheGreatCatAdorer. The defmacro declaration needs to be at the top level, you cannot put it inside a let (same applies to define). Another issue is that the expanded code cannot contain multiple forms, if you need that you have to wrap them in [package null [] ....] so that they become a single form.

Btw, for let bindings you should use upper-case names, otherwise the code may not be portable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants