简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM