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

hy2py generates invalid Python #923

Closed
tmbdev opened this issue Aug 26, 2015 · 5 comments
Closed

hy2py generates invalid Python #923

tmbdev opened this issue Aug 26, 2015 · 5 comments

Comments

@tmbdev
Copy link

tmbdev commented Aug 26, 2015

Running hy2py generates invalid Python output:

$ cat test.hy
(defn test.+ [] 0)
$ hy2py test.hy
def _hy_anon_fn_1():
    return 0L
test.+ = _hy_anon_fn_1
test.+
$

I think this should either quote or give an error at compilation time.

@refi64
Copy link
Contributor

refi64 commented Aug 26, 2015

@tmbdev This is known and intentional. hy2py is really just a debugging tool (which is really handy when writing macros).

@gilch
Copy link
Member

gilch commented Sep 10, 2015

hy2py would certainly be more useful if the output was valid Python. With that we could use Hy with things that expect Python code instead of compiled Python. (Cython?)

I wonder if we could add a switch to the tool to make it convert all the identifiers to their punycode equivalents? Would that be enough to make all the output valid Python?

@ailijic
Copy link

ailijic commented Sep 10, 2015

@gilch
Hi, can you elaborate on possible/potential use cases for such a feature?
I am not aware of any libraries that take python code as an argument. If you have a situation where you need to pass in python code directly could you just create a python program, call your hy program, and then just return to python when needed?

@gilch
Copy link
Member

gilch commented Sep 10, 2015

In #934 @kirbyfan64 pointed out that Cython uses a custom parser, so it needs source code, not just a compiled module. Hy doesn't support Cython's type annotations, but you supposedly get considerable speedup even without them. If you just imported a Hy module from a Cython program, there wouldn't be any speedup for the Hy module, but if hy2py could generate valid Python, then you could compile that output with Cython and get the speedup.

I also wonder about Pyjamas, which lets you run Python in the browser. It's supposed to generate JavaScript from Python AST, but they're probably making assumptions about it containing valid Python identifiers. I haven't actually tried it, but I don't think Hy would work. But if hy2py could generate valid Python, then you could translate that output to JavaScript using Pyjamas, and use Hy in the browser.

@Foxboron
Copy link
Member

Closing this. @gilch feel free to make a new issue about the switch idea \o/

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

5 participants