-
Notifications
You must be signed in to change notification settings - Fork 0
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
Rename def to setv; adjust require statements for let macro. #2
Rename def to setv; adjust require statements for let macro. #2
Conversation
I think the current problems are due to a change in the Perhaps it has to do with the way in which its bindings are assigned/bound: => (let [a 2 a 1] a)
_hyx_XsemicolonXletXvertical_lineX1270 = {}
_hyx_XsemicolonXletXvertical_lineX1270['a'] = 2
_hyx_XsemicolonXletXvertical_lineX1270['a']
2
=> None |
The changes look fine to me. Any idea why the tests fail, and how they could be updated to work with newer Hy? (I don't have the time to dive into it myself, sadly.) |
That's a bug in the let macro, thanks for finding it. It looks like the binding names can only be used once. I'll fix it soon. In the meantime, you can use nested
|
@gilch, thanks for the heads-up! I created an issue for it: hylang/hy#1645. |
Tests look better now, thanks a lot! I'll have a bit of time this coming Friday, will look into this (and the adderall PR) then. |
All right, I think I found and corrected the remaining issues (the current test failure is something entirely different and ostensibly Python 3.3 related), but I'm also finding some aspects of Hy macros that are quite confusing. For instance, the following doesn't work without an additional => (import [monaxhyd [monads]])
=> (require [monaxhyd.core [*]])
=> ;; (require [hy.contrib.walk [let]])
=> (domonad monads.identity-m [[a 1] [b (inc a)]] (+ a b))
from hy import HySymbol
from hy.core.language import inc
let([_hyx_XsemicolonXgXvertical_lineX1236, monads.identity_m, m_bind,
_hyx_XsemicolonXgXvertical_lineX1236[HySymbol('m-bind')], m_result,
_hyx_XsemicolonXgXvertical_lineX1236[HySymbol('m-result')], m_zero,
_hyx_XsemicolonXgXvertical_lineX1236[HySymbol('m-zero')], m_plus,
_hyx_XsemicolonXgXvertical_lineX1236[HySymbol('m-plus')]], m_bind(1, lambda
a: m_bind(inc(a), lambda b: m_result(a + b))))
Traceback (most recent call last):
File "/home/bwillard/projects/code/python/hy/hy/importer.py", line 199, in hy_eval
return eval(ast_compile(expr, "<eval>", "eval"), namespace)
File "<eval>", line 1, in <module>
NameError: name 'let' is not defined It seems odd to require macros that are dependencies of imported macros, no? Am I doing the imports incorrectly? |
I've created a PR for the remaining issue: |
I think you are doing the imports right, and it is a reasonable expectation that dependencies would get require'd too. But for the time being, the workaround is acceptable. As I already merged #3, merging this too. Thank you for your work on updating monaxhyd (and adderall) to recent Hy versions! |
@brandonwillard you should be able to put a Alternatively, you could use I think the namespacing of macros is one area where Hy needs improvement. |
@gilch, the latter approach, with Otherwise, is there an existing issue that tracks this problem/feature for |
@brandonwillard I don't know that we have exactly that issue, but these three look related.
It might not work as well as you'd hope. It's actually not what I'd recommend in this case, now that I think about it. Both of my suggestions have problems. Including But using macroexpand-all like that could end up using the wrong macro too. Which symbols count as macros depends on the current expansion context. The A more Clojure-like symbol namespace system could deal with this pretty easily, but for now, if you want to do this right you'd have to use gensyms. So, wrap the return code in a do, like so (defmacro/g! [...]
`(do
(require [hy.contrib.walk [let :as ~g!let]])
(~g!let [... This will add a gensym'd let to the client module's expansion context, which should prevent any kind of accidental capture. |
Small adjustments for recent Hy updates.