10 ms·
Lisp-stick on a Python
- ngcc_hk 4y agoWonder why not syntax totally common lisp so one does not need to change with switch to turn on certain or full Hy features. It is a bit confusing this partially Python partial Common Lisp then throw in a “!” for defmarco …
- deleted 4y ago[deleted]
- ravi-delia 4y agoHy has syntax primarily based on Clojure, but with big changes to get it closer to Python semantics. It bears little resemblance to CL for a reason.
- bragr 4y agoHylang is a great way to dip your toes into Lisp style languages IMHO since you have the entire python ecosystem at your fingertips. It was very eye opening to rewrite some scripts in Hy. I'm not sure if I'm ultimately a fan of lisp, but I had a lot of fun learning Hy a while back after discovering it in another HN post.
- tomcam 4y agoI can imagine speed being a real problem in production?
- lordgroff 4y agoYou can transpile to Python. You get a bunch of necessary symbol definitions but that's about it. I doubt anyone uses hy in production for completely other reasons, would love to be proven wrong.
- wiseowise 4y agoPeople use Python in production, why not Hy?
- kdmccormick 4y agoThere are plenty of reasons not to add a transpilation step to production code: * Looking at stack traces is suddenly so much harder and involves reverse-engineering the transpiler unless your transpiler is sophisticated enough that it can de-transpile the stack traces back to the source language. * You're adding a step to your build pipeline. * You're taking on the risk of bugs or security issues that may exist or be introduced to the transpiler itself. * Your developers need to learn both the source and target languages. * If the transpiler project is abandoned, you have to begin maintaining it yourself, or you need to de-obfuscate your transpiled code enough to make it your canonical code. I think that anyone who used CoffeeScript in the late 2000s / early 2010s understands the pain of using a transpiled language that wasn't worth the trouble. Not to say that one should never transpile, or that Hy's not worth it or not production ready! Just that, there are things to consider, and how much you need to consider them depends on what your "production" is.
- Foxboron 4y agoHy isn't transpiled though, it's compiled into valid python bytecode so some of the traditional issues around transpilation doesn't apply to Hy.
- bayesian_horse 4y agoHylang doesn't add anything to your build pipeline, because of some tricks. Stack traces aren't that useful in Lisp but the bytecode refers to the actual source code positions. Multiple languages are less of an issue when you have a small team or a team of one. I'd be willing to use Hylang in production. I wouldn't go all-in, but rather pick something that looks like it needs a DSL. You can still interface with Python code interchangeably whenever you want, so there really is not much pain to abandon the attempt completely.
- 4y ago
- thrown_22 4y agoQuestion from the last time this came up: have they added let/letrec into the language yet? The last time I it looked like they had not.
- alschwalm 4y agoLooks like it: https://docs.hylang.org/en/stable/api.html#let https://docs.hylang.org/en/stable/api.html#let I recall hearing it had been implemented a while back, seems like it's true!
- thrown_22 4y agoNice. They do seem to have filled out the language nicely.
- lordgroff 4y agoLet is indeed there now.
- kagevf 4y agoThat's good news ... I thought they had added it but were forced to remove it. I think this will make Hy a bit easier to use, especially for those who are more comfortable with CL or Scheme than Python :)
- giantdude 4y agoI don't get it. I am a Smug Lisp Weenie. Lisp is not a syntactic sugar - the only reason it looks like it does is for metaprogramming. Those parens are not syntax - they indicate the underlying structure of the code, a tree which may be manipulated by Lisp macros. Why would anyone pretend to program in Lisp without any benefit? Also, Python is the worst imaginable engine for running Lisp. [correction: I see there are some kind of macros...]
- wiseowise 4y ago> Why would anyone pretend to program in Lisp without any benefit? Because it is superior way of writing a program. Pure, consistent and unambiguous.
- agumonkey 4y agothink of it as clojure to java, even without embodying the whole lisp ethos, it gives you a lispy base to write python code, plus extra niceties (threading -> IIRC) plus you get to benefit from paredit under emacs
- skissane 4y agoClojure is more than just a Lisp for the JVM – it is a Lisp for the JVM with a big focus on immutable data structures – whereas traditionally most Lisps put mutability first instead. There are other Java-based Lisps, such as Armed Bear Common Lisp (ABCL), which are more traditionally Lisp-like in this regard. I think Hy is more of a traditional Lisp, since it shares Python's native focus on mutable data rather than trying to foreground immutability.
- teewuane 4y agoWhat am I looking at here? And what is it for?
- gleenn 4y agoMuch like Clojure is lisp on the Java virtual machine, Hy is a lisp on Python. There are definitely plenty of ways in which lisps vary and I've heard Hy tends to follow some Pythonisms more closely than other lisps may follow their host languages.
- sampo 4y agoThis might be a better starting point: https://docs.hylang.org/en/stable/whyhy.html https://docs.hylang.org/en/stable/whyhy.html Shortened from there: Hy (or “Hylang”) is a multi-paradigm general-purpose programming language in the Lisp family. It’s implemented as a kind of alternative syntax for Python. Hy provides direct access to Python’s built-ins and third-party Python libraries, while allowing you to freely mix imperative, functional, and object-oriented styles of programming.
- deleted 4y ago[deleted]
- Foxboron 4y agoIf someone thinks the Hy mascot, Cuddles the Cuttlefish, looks awfully familiar to a certain crustacean mascot, you would be correct! They are both drawn by Karen Rustad Tölva! https://www.aldeka.net/ https://www.aldeka.net/
- ashok-syd 4y agoShe has great Art and Designs - thanks for sharing the link to her bio/portfolio
- john-radio 4y agoAmazing! Ferris is loved and Tölva's art at that site is so nice and funny. Very cool and appropriate that she's also managed to have "Rust" as part of her name.
- ericvsmith 4y agoSee also PEP 638 – Syntactic Macros https://peps.python.org/pep-0638/ https://peps.python.org/pep-0638/
- smitty1e 4y agoYou beat me to it. One wonders if this might become a python13 feature, whenever they get around to branching the CPython repository.
- ericvsmith 4y agoI’m contemplating pushing for it in 3.12, but it’s probably more than a year’s worth of work to implement and shepherd the PEP through. So 3.13 is more likely. And I’m not sure it won’t get shot down anyway. It’s a big step for Python.
- smitty1e 4y agoI'm still not even using Typing, but, in the feature wars, it's an obvious step in the direction of maintaining featuritis parity with c++. /snark
- BiteCode_dev 4y agoGiving people the ability to create more useless unsupported DSL in a world where people think YAML dialects in the CI was a good idea will damage Python in the long run. And I say that while I wished I could use macro several times in Python because the syntax was lacking.
- kortex 4y agoI'm likened to agree. As much fun as syntactic macros in python would be, and despite all the doors it would open, it would really kick up the potential complexity. Heck, folks were complaining about pattern matching and the walrus operator. I mean maybe the council will go with it, but I'm bearish. I do really like the idea of jit macros and zero-overhead decorators though.
- warent 4y agoWhy Hy? Hy (or “Hylang” for long; named after the insect order Hymenoptera, since Paul Tagliamonte was studying swarm behavior when he created the language) I'm spending my HN karma to make this petty comment that if the first sentence of your docs immediately opens up with the story of how you named your project, I instantly don't want to use it or read any more. It's like when you open a cooking recipe on a website and you get the author's entire life story
- ahungry 4y agoThis was a trend in the early 2010s on a lot of Clojure projects
- eCa 4y agoI’m going to follow up with a slightly more pertinent question: Why use a cuttlefish as the logo when the language is named after another animal? Missed opportunity to spread the knlowledge about the Hymenopteras…
- a9h74j 4y agoNo expert, but the shape of the head of the cuttlefish (as drawn) somewhat suggests a pair of parentheses.
- vindarel 4y agoIf you want to use Python libs from CL, see py4cl: https://github.com/bendudson/py4cl https://github.com/bendudson/py4cl the other way around, calling your efficient CL library from Python: https://github.com/marcoheisig/cl4py/ https://github.com/marcoheisig/cl4py/ There might be more CL libraries than you think! https://github.com/CodyReichert/awesome-cl https://github.com/CodyReichert/awesome-cl (or at least a project sufficiently advanced on your field to join forces ;) )
- khun3 4y agoi like
- mikedelago 4y agoHy is great fun - the batteries of python and the expressiveness of lisp. I've written a few scripts here and there, and I've had a fantastic time with it.
- p-e-w 4y agoI've been hearing claims my entire programming career about how Lisp is supposedly "superior" to mainstream programming languages, but I've never seen a concise code example that actually demonstrates this. For instance, it's easy to demonstrate how Rust is superior to C: Just show a short piece of code where an array is returned from a function. In C, this will involve raw pointers and manual memory management with all associated safety and security pitfalls, whereas in Rust you just return a `Vec` and everything is taken care of. Simple, obvious, real-world superiority. How does such an example for Lisp look like? I'd love to see 10 lines of Lisp that show me something that: 1. I can't easily do in, say, Rust. 2. Actually matters in practice.
- deleted 4y ago[deleted]
- eliben 4y agoI genuinely like Rust, but it's pretty amazing that you managed to write a comment on this article and make it about Rust. Peak HN :-) Re Lisp's superiority - Lisp was certainly a superior language when it was devised many decades ago, but over time much of its comparative advantage has been absorbed by other languages. Starting in the 90s when productive, GC'd scripting languages like Python started being prominent this trend accelerated. For a nice discussion of this see https://norvig.com/Lisp-retro.html https://norvig.com/Lisp-retro.html
- TurboHaskal 4y agoIs someone willing to go back in time and let comp.lang.lisp know about Rust?
- Sinidir 4y agoI mean i would but i don't know wether going back in time would pass the borrow checker.
- LanternLight83 4y agoI'd say the most satisfying experiences I have with lisp are a cross between clean abstractions and light code-golfing. To call out specific approaches, I'd highlight anaphoric macros, code-walking via (symbol-)macro-let [1], and the freedom to control when expressions evaluated (generally at read-time, compile-time, or run-time) for optimization [2][3]. [1]: https://letoverlambda.com/index.cl/guest/chap5.html#sec_ https://letoverlambda.com/index.cl/guest/chap5.html#sec_ [2]: Compiler macro chapters aren't free, but I guess read-time is covered here https://letoverlambda.com/index.cl/guest/chap4.html#sec_1 https://letoverlambda.com/index.cl/guest/chap4.html#sec_1 [3]: https://irreal.org/blog/?p=809 https://irreal.org/blog/?p=809 / https://web.archive.org/web/20140711171755/symbo1ics.com/blog/?p=1352 https://web.archive.org/web/20140711171755/symbo1ics.com/blo...
- bitwize 4y agoThese days I'm a fan of Calysto Scheme: https://github.com/Calysto/calysto_scheme https://github.com/Calysto/calysto_scheme It's not blazing fast, but it's Scheme -- not paren-y syntactic sugar around Python.
- pharmakom 4y agoLisp examples always use addition, but this is what trips me up (- 2 3) And (- 4 3 2)
- alexeiz 4y agoHylang is fun and everything, but they make a lot of breaking changes in minor releases. It was "(import [module [function]])" in 0.20 and now in 0.25 it's "(import module [function])" and the old code doesn't compile anymore.