• cooljoseph 2 hours ago

    I was having some difficulty figuring out how Hy actually is translated to Python (and wasn't even sure if it was compiled or interpreted). Eventually I found on Wikipedia the following: > Hy is a dialect of the Lisp programming language designed to interact with Python by translating s-expressions into Python's abstract syntax tree (AST).

    Also, looking at the code on Github suggests this compiler is written in Python (see https://github.com/hylang/hy/blob/master/hy/compiler.py).

    I kind of wish this was made more clear on the main website. Perhaps, instead of introducing Hy as "a Lisp dialect that's embedded in Python", introduce it as "a Lisp dialect that compiles to Python's AST". The words "embedded in Python" don't make it very clear just how it's embedded into Python. The various ways you can embed a Lisp look very different and have very different tradeoffs.

    For example, off the top of my head, I could "embed" a Lisp by writing an interpreter (in C if I care about performance) and letting it be called from Python, perhaps passing in a Python list instead of a string to make it more "native". Or I could "embed" a Lisp by compiling to Python bytecode. Or I could "embed" a Lisp by translating it directly to Python source code. Etc.

    Regardless, interesting project!

    • wodenokoto 26 minutes ago

      From the readme / github page:

      > Hy is a Lisp dialect that's embedded in Python. Since Hy transforms its Lisp code into Python abstract syntax tree (AST) objects, you have the whole beautiful world of Python at your fingertips, in Lisp form.

      • Kodiologist an hour ago

        > this compiler is written in Python

        Yes, that's right. Hy is not self-hosted.

        > The various ways you can embed a Lisp look very different and have very different tradeoffs.

        Hy itself provides options. Typically the process is that the Hy source code becomes Python AST objects, which Python then complies and executes, but you can also translate the Python AST objects into Python source text. Or you can use Python from Hy or vice versa: https://hylang.org/hy/doc/v1.0.0/interop

        • rcarmo an hour ago

          The "embed" part stems from the fact that you can mix Python and Hy in a project with bi-directional calling. Works great, because it is all Python byte code in the end.

          • PuercoPop an hour ago

            The original hy annoucement makes it clear that they embed a Lisp by compiling with Python bytecode. You can see it in the following video about the 16:25 mark

            https://m.youtube.com/watch?v=1vui-LupKJI

          • vintagedave 5 minutes ago

            I loved the HYPE POST.[0] I work with corporate software. It is absolutely brilliant.

            [0] https://github.com/hylang/hy/discussions/2609

            • HexDecOctBin 2 hours ago

              Congrats! Two questions:

              1. Does it support REPL-driven development? (condition system, breakloop, etc.)

              2. Is there a standalone distribution? Distributing python in itself is a hassle, ideal situation would be to simply distribute a single Hy binary that contains all dependencies within it (either statically linked or as a zip file extracted in tmp directory).

              • Kodiologist an hour ago

                1. I don't know what a breakloop is. Hy uses Python's exception system, which is more like a traditional exception system than Common Lisp's condition system.

                2. No, sorry.

                • wrs an hour ago

                  A breakloop is a REPL operating in the context of condition handling. When a condition is signaled, you can use the breakloop to modify state and direct how the condition should be handled (including fixing something local and letting the current function proceed by ignoring the condition).

                  Seems like that would only be doable by altering CPython to at least have a hook in the initial exception processing (or maybe there is some magic double-underscore thing for that already?).

                  • perihelions 9 minutes ago

                    Oh wow, I could have benefited from this knowledge 10 minutes ago! Apparently it's simply the hotkey "e" in sldb. This is nice.

                    I had been doing silly things to get at *stack-local* variables in the context of a (break) point.

                    • Kodiologist 29 minutes ago

                      I see. That's pretty similar to the feature set of [pdb](https://docs.python.org/3/library/pdb.html). You may then logically ask "Does Hy support pdb?". The answer is "sort of". I've fixed one or two bugs, but we don't test it. I suspect there are various features of pdb that assume Python syntax and would need some hooks to get working properly with Hy.

                  • tosh an hour ago

                    not a standalone distribution but:

                      uvx hy@1.0.0
                    
                    gets you into the Hy REPL

                      echo '(print "hi hn")' > hi.hy
                      uvx hy@1.0.0 hi.hy
                    
                    prints "hi hn"

                    https://docs.astral.sh/uv/guides/tools/#running-tools

                    (context: uv can install and manage python versions)

                    • rcarmo an hour ago

                      I managed to do 2, sort of, with py2app and judicious hacking. You can compile everything to byte code and use Python "single file" deployment tools.

                    • knlb 3 hours ago

                      Congratulations -- and thank you! I've been playing with Hy on and off (tried to do transformers with it, and then released https://github.com/kunalb/orphism written in hy). Time to pick it up again and take it for a spin

                      • agentultra 2 hours ago

                        Wow! It has come such a long way since its early, humble beginnings.

                        I saw the original lightning talk that introduced Hy to the world at Pycon those ages ago. Soon after I met Paul and started contributing to the early versions of Hy. I was responsible for the CL-style kwargs (you’re welcome), some minor innards, and a library or two.

                        Whimsy is useful, especially to keep enthusiasm up. It’s nice when hackers can be hackers and not every thing is business.

                        While I haven’t been involved in years it brings a smile to me face to see the project continues apace. What a great milestone!

                        • marmaduke 3 hours ago

                          I enjoyed the less serious part a lot. I wish more programming related projects could embrace the whimsical. That might the best way to honor the python tradition in any case :)

                          • Kodiologist 3 hours ago

                            I eliminated a lot of whimsy from Hy and its documentation years ago because it was distracting and created noisy test failures, but I did go too far at some point, and have tried to reintroduce a little whimsy more recently.

                          • rcarmo 2 hours ago

                            At long last! Now I can finally clean up https://github.com/rcarmo/sushy (I've been poking at it over the years, but every time I upgraded hy portions of the syntax broke, or things would get moved in and out of the hyrule package, etc.)

                            By the way, Hy works really well inside https://holzschu.github.io/a-Shell_iOS on the iPad, although the syntax highlighting in vim/neovim needs to catch up to the 0.29+ releases and async.

                            Although I've tried using Fennel and Guile instead over the years, having access to Python libraries and ecosystem is preferable to me, and with async I can do some very nice, efficient API wrangling (doing HTTPS with fine-grained control over socket re-use and headers remains a pain in various Schemes, so I very much prefer using aiohttp)

                            • instig007 2 hours ago

                              You can get FP compositions without throwing away Python syntax (as Hy does): https://github.com/thyeem/foc

                              • BeetleB an hour ago

                                Any downsides to using Hy (over Python)? Other than my coworkers don't know Lisp?

                                More concrete: Are there Python language features I can't use in Hy? Or performance penalties in using Hy?

                                • rcarmo an hour ago

                                  You take a little performance hit upon initial startup (from a clean filesystem, while __pycache__ folders are created). Other than that, mostly everything is the same.

                                  I'm now figuring out how to pack images to OpenAI REST calls (using my own REST wrapper), and everything is peachy. Here's my test snippet (mostly to b64encode the file):

                                      (import aiohttp [ClientSession]
                                              base64  [b64encode]
                                              asyncio [run])
                                  
                                      (defn :async pack-image [filename]
                                        (with [h (open filename "rb")]
                                          {
                                            "type" "image_url"
                                            "image_url" { "url" f"data:image/jpeg;base64,{(.decode (b64encode (.read h)) "utf-8")}" }
                                          }))
                                  
                                      (defn :async main[]
                                        (print (await (pack-image "request.hy"))))
                                  
                                      (run (main))
                                  
                                  This shows you async, context managers, selective imports, f-strings... etc. All that you need, really.
                                  • Kodiologist an hour ago

                                    > Are there Python language features I can't use in Hy?

                                    At the semantic level, no. I work to cover 100% of Python AST node types with Hy's core macros. It does take me a little bit to implement a new core macro after the CPython guys implement a new feature, but you can always use the `py` or `pys` macros to embed the Python you need, should it come to that.

                                    > Or performance penalties in using Hy?

                                    Compiling Hy (that is, translating it to Python AST) can be slow for large programs (I've seen it top out at about 3 seconds), but at runtime you shouldn't see a difference. Hy always produces bytecode, which can be used to skip the compilation step if the code is unchanged.

                                    • Qem 30 minutes ago

                                      Lack of self-contained tooling. Idle doesn't work with Hy. You'll probably need to fiddle with Emacs to set your environment first, before being able to do anything beyond playing with the language in the REPL.

                                    • kayo_20211030 3 hours ago

                                      Very exciting. I'm in awe of the long-term commitment (over 10 years) that was required to get this to 1.0.0. It renews my faith. Well done.

                                      • blumomo 3 hours ago

                                        Congratulations! I once bought your eBook on Hy, and still today I regularly receive notifications about your book having been updated. Thank you for your steady contributions. I really want to use Hy in one my production apps one day.

                                        • Kodiologist 3 hours ago

                                          The author of the e-book is a different guy, Mark Watson. He isn't involved in the development of the language.

                                          • blumomo 2 hours ago

                                            Oh, thanks. He seemed so enthusiastic about Hy :-)

                                            I just read through the author list on the Hy repo and had a glimpse into their blog posts. Cool stuff, great work.

                                        • paultopia 3 hours ago

                                          EXCITING! Can't wait to give it a spin!

                                          (Does `let` work? I remember that being a barrier for a while.)

                                          • Kodiologist 3 hours ago

                                            Remarkably enough, yes, we got it to work, on our 3rd or 4th try.

                                            • rcarmo an hour ago

                                              Yep. I use it a lot.

                                          • anovick 3 hours ago

                                            Congrats!

                                            Could you compare the language with Clojure?

                                            • Kodiologist 3 hours ago

                                              Well, this is a little embarrassing: Clojure was one of the biggest influences on Hy in its youth, but that was mostly before I got involved in 2016. I never actually learned Clojure. So hopefully somebody who knows both Hy and Clojure well can answer. I can tell you that at run-time, Hy is essentially Python code, so Hy is more tightly coupled to Python than Clojure is to Java; a better analogy is CoffeeScript's relationship with JavaScript.

                                              I get the impression that Clojure tries to convince the programmer to avoid side-effects a lot more strenuously than Hy does, but it's still not a purely functional language, so I don't know how consequential that is in practice.

                                              • a57721 36 minutes ago

                                                Clojure has a good collection library with immutable/persistent data structures, but as a language it allows side effects and has some mechanisms to manage them. It is also possible to call any Java method from Clojure.

                                                Clojure does not work with Java ASTs, it translates into JVM bytecode directly.

                                              • chrisrink10 2 hours ago

                                                I haven't used Hy, but I am the maintainer of a Basilisp which also compiles to Python and aims for reasonably close compatibility with Clojure if you're interested.

                                                https://github.com/basilisp-lang/basilisp

                                                • anovick an hour ago

                                                  Cool project!

                                                  Wondering how custom immutable data structures fit in with the Python ecosystem.

                                                  Particularly, I know that NumPy arrays and Pandas Series/DataFrames are the popular data structures used in research computing in Python (for Statistics, Data Science, Machine Learning etc.). These data structures afaik are mutable, however (for performance reasons), so at least the aspect of immutability from Clojure cannot be easily integrated with the Python ecosystem.

                                                  • chrisrink10 an hour ago

                                                    This project is much younger and used by many fewer people than Hy, so I couldn't really speak to this besides my own opinions. The few who have started using it and contributing seem to just be using it as a way to write Clojure while interacting with popular Python libraries and tools. Kind of the same way that interacting with the Java ecosystem is often more pleasant from Clojure (IMO) than in Java itself.

                                                    I've tried to facilitate strong Python interoperability despite the variety of otherwise incompatible features of each language. It's trivial to work with immutable data structures using Clojure idioms and then convert them to Python data structures (as needed) at the boundaries, but the immutable data structures used by Basilisp are also generally compatible with Python's core (read-only) interfaces so that conversion may also not be necessary if you aren't expecting the called function to perform any mutations.

                                              • agumonkey 2 hours ago

                                                Congrats. It's been a great pleasure to watch it evolve. :)

                                                • cab404 an hour ago

                                                  Ну, молодцы.

                                                  • chrisrink10 2 hours ago

                                                    Congrats on the release! Very impressive.

                                                    • tosh 3 hours ago

                                                      Does Hy also work with Mojo?

                                                      • Kodiologist 3 hours ago

                                                        I'm not sure. I was going to say that Mojo is proprietary software and so I've never tried it, but I just checked and apparently it's free now. If nothing else, you can probably get a lot of Hy code to run on Mojo via `hy2py`, if Mojo supports a lot of Python as it claims to.

                                                        Edit: actually, confusingly, the GitHub repository for Mojo doesn't have an interpreter. The language is still proprietary.

                                                        • tosh 2 hours ago

                                                          Thank you for the hy2py pointer and kudos @ 1.0.0!

                                                        • rcarmo an hour ago

                                                          Not sure either, but it should. I do test it every year or so with pypy.