Requiring `hy' macro with `raise' function triggers `raise' on `require'

49 views Asked by At

When trying to require the following macro in another file, the raise seems to be triggering immediately:

(defmacro assert [a [b True] [message None]]
    `(unless (= ~a ~b) (raise (AssertionError (or ~message ~a)))))

This results in an AssertionError: True.

Steps to reproduce (sometimes works, and sometimes doesn't):

echo '(defmacro assert [a [b True] [message None]] `(unless (= ~a ~b) (raise (AssertionError (or ~message ~a)))))' > a.hy
echo '(require a [assert])' > b.hy
echo '(assert True)' >> b.hy
hy b.hy
1

There are 1 answers

0
ShadowRylander On

In another instance of Python evaluating function arguments before names, as stated by Kodiologist in their comment here and their answer on one of my previous questions "Non-existent hy macros runs assertions, but fails appropriately with everything else", the issue was that unless didn't trigger a NameError when it didn't exist, since it was moved from the hy core to hyrule a little over a year ago.