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

Python-> hy converter #1721

Open
johanatan opened this issue Jan 8, 2019 · 14 comments
Open

Python-> hy converter #1721

johanatan opened this issue Jan 8, 2019 · 14 comments
Labels

Comments

@johanatan
Copy link

johanatan commented Jan 8, 2019

Hi,

Does there exist a Python -> hy converter? If not, how difficult would it be to create?

I’d imagine that the project would get a lot more adoption with this in place as it would allow those who will never be convinced of the goodness of s-exprs to interoperate more closely with those who have been convinced.

@gilch
Copy link
Member

gilch commented Jan 8, 2019

https://github.com/woodrush/py2hy

I don't think it's up to date though. See #876.

@brandonwillard
Copy link
Member

brandonwillard commented Jan 8, 2019

Not an immediately usable answer, but I recently wrote something about Hy <-> Python AST (i.e. round-trip) compilation: Readable Strings and Relational Programming in Hy.

@johanatan
Copy link
Author

@brandonwillard did you mean "equivalent and not exactly equal"? rather than:

might only be equal and not exactly equivalent

@johanatan
Copy link
Author

And, very interesting article btw.

Since this doesn't quite seem possible in practice currently, does anyone have advice for mixing Hy in to an existing Python team? Assuming that co-workers want to continue to use Python syntax and I want to use Hy syntax, what is the best way at this point in time to facilitate it?

I was thinking that I could "own" any modules I write in Hy, be responsible for any feature or modification requests to them and if at some point in time others take a keen enough interest in it, do a one-way translation to Python and let them "takeover". Would that work?

@brandonwillard
Copy link
Member

@brandonwillard did you mean "equivalent and not exactly equal"? rather than:

might only be equal and not exactly equivalent

Yeah, looks like it.

@Kodiologist
Copy link
Member

Since this doesn't quite seem possible in practice currently, does anyone have advice for mixing Hy in to an existing Python team? Assuming that co-workers want to continue to use Python syntax and I want to use Hy syntax, what is the best way at this point in time to facilitate it?

I was thinking that I could "own" any modules I write in Hy, be responsible for any feature or modification requests to them and if at some point in time others take a keen enough interest in it, do a one-way translation to Python and let them "takeover". Would that work?

Short of getting your co-workers interested in Hy themselves, that's probably the way to do it, yeah. The code produced by hy2py isn't always the prettiest, but it's an excellent starting point for a Python translation of a Hy program, if nothing else. And it should be 100% semantically equivalent to the Python original, as of Hy 0.15.

@loynoir
Copy link

loynoir commented Feb 28, 2021

From perspective of a hy freshman without lisp experience, it would be a lot better if there's an offical tool.
An officail transpiler can make hy -> py and translate back py -> hy, and content stay same.

@woodrush
Copy link
Contributor

Hi, I'm the author of py2hy. I'm sorry I wasn't able to work on py2hy for a long time. I'm now planning to update it for compatibility with the latest version. Congratulations on Hy reaching Version 1.0!

Depending on how the py2hy project turns out, I am thinking of merging py2hy to an official command inside Hy's main repo. The first issue for this is relicensing, for license compatibility with Hy. I initially licensed py2hy with LGPL and am planning to relicense it to Expat to make sure we have license-compatible code. I'm fully OK with this, but since I'm currently having a pull request to py2hy that updates it to be Hy 0.18-compatible, I'm currently asking the author of the pull request if they're OK with relicensing as well. I also sent an email to the author. Even after merging the pull request, I probably still need to update things to make it Hy-1.0 compatible, which I plan to work on as well. Once I get the licensing issue resolved I am planning to start rewriting the code for compatibility.

@Kodiologist
Copy link
Member

To be clear, we're still not at 1.0. Work you do to update your code for the current master will help you get to 1.0 compatibility, but 1.0 still doesn't exist yet.

I am thinking of merging py2hy to an official command inside Hy's main repo

If you can get your program to work without actually being part of Hy itself, then by all means continue with that. Hy is already big and complicated, so there's no benefit to trying to squeeze more stuff into the same repository. I'm open to moving your project into the hylang organization if you'd like to make it more official, though.

LGPL is fine by me. I'm pro-copyleft, and I would've GPLed Hy if I'd been the one to start it.

@woodrush
Copy link
Contributor

Sorry, I was looking at the repository's tag for the version. I checked pip and saw that we're at 0.20.0 now. I'll be working on the compatibility with that version.

I'm open to moving your project into the hylang organization if you'd like to make it more official, though.

Thanks for your support. I'll definitely be looking into that option once I finish it.

LGPL is fine by me. I'm pro-copyleft, and I would've GPLed Hy if I'd been the one to start it.

Thanks. Due to the current situation with py2hy I might stick with LGPL.

@Kodiologist
Copy link
Member

Kodiologist commented Jan 21, 2022

I checked pip and saw that we're at 0.20.0 now.

Not exactly; that's just the last non-alpha release. All further releases have been and will be alphas until 1.0, whenever that is. Your choice whether to aim for 0.20.0 or follow the alphas. Update: since #2245, we're back to making 0.* releases.

@woodrush
Copy link
Contributor

I see. I'll make various versions for py2hy as well then, corresponding to the Hy versions.

@asimjalis
Copy link

asimjalis commented Dec 9, 2022

One workaround is to wrap the Python code into pys and then call the functions from Hy, like so:

(pys "
def hello_world(): 
    print('Hello, world!')
")
(hello-world)

Outputs: Hello, world!

I find this helpful when I want to use Python code snippets in Hy.

@Kodiologist
Copy link
Member

You can also just import Python code from a file, and there are other options; see "Interoperability" in the manual.

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

No branches or pull requests

8 participants