34 ms·
Hy – A Lisp-flavored Python
- kzisme 9y agoShout out to @paultag (Author/Creator of Hy) - he's an awesome guy who has written some really cool stuff.
- boxy_brown 9y agoThis, Paul is someone I look to as a model open source contributor in so many ways. https://twitter.com/nedbat/status/861696880790704128 https://twitter.com/nedbat/status/861696880790704128 > How many people can say they have worked with [Sally] Yates, and have written exemplary Dockerfiles?
- paultag 9y ago<3
- asimjalis 9y agoI have been using Hy as an alternative to Python. It is delightful to use. Highly recommended.
- cheez 9y agoWhat kind of projects have you used it for?
- rcarmo 9y agoMy blog/wiki engine is written in an older version of Hy: https://github.com/rcarmo/sushy https://github.com/rcarmo/sushy I'm currently re-writing it in Python 3.6 because Hy has taken a hard stance in backwards compatibility and deprecated "let" (with a replacement macro, but still) and isn't tackling async (both for understandable, but sad reasons), so it doesn't really work for me anymore. But while it did, I loved it to bits. Python with a LISP syntax is just wonderful, and if someone ever finds a way to add back the stuff I like, I'm more than willing to deal with the quirks.
- chuckdries 9y agoI know python, and last semester I took a class that briefly touched (lightly kissed?) LISP for a few weeks. I have a passing familiarity and I really loved the very small amount that I saw. I'd like to learn more, can you go into more detail on the usage of let and how one would go without it?
- hood_syntax 9y ago> lightly kissed How romantic!
- flavio81 9y ago> I'd like to learn more, can you go into more detail on the usage of let and how one would go without it? Welcome to the wonderful world of Lisp. I'd recommend to you to install Portacle (the Portable Common Lisp Environment), this allows you to code in Lisp straight away. As for tutorials, "Practical Common Lisp" (free online book) is fun, modern, and excellent for introducing you to most CL concepts, including of course use of let, let*, etc.
- taneem 9y agoThe online demo is amusing/creative: https://try-hy.appspot.com/ https://try-hy.appspot.com/
- nathancahill 9y agoThis is my go-to for toy projects over the last couple years. Great execution all around. Be aware, if you don't like puns, this isn't the language for you.
- sn9 9y agoSo you're saying that if you don't like puns, you should get off your Hy horse?
- kerkeslager 9y agoNothing so aggressive. He's just saying they hold puns in Hy esteem.
- alschwalm 9y agoHy is a great project. One unfortunate thing, though, is that no one has been able to successfully implement `let`, which makes writing idiomatic lisp almost impossible. I'm curious if anyone can actually prove it can't be done or is just very difficult (or too slow to be useful).
- rcarmo 9y agoThis. See my other comment for a sizable Hy example and more info, but the lack of "let" mostly killed it for me.
- nnq 9y ago> but the lack of "let" mostly killed it for me Can you give an example of code that is improved by let significantly? ...and can't be rewritten in a more readable way without it?
- hk__2 9y ago> Can you give an example of code that is improved by let significantly Any piece of code that uses a variable.
- nnq 9y agoI'd be more inclined to day that let mostly encourages you to write zillion-line functions (instead of lots of small ones), simply because with it you "mentally can" since you can see the scope of variables better. But.. do you really prefer to write huge functions instead of smaller ones? Also: I think Python's default args being evaluated at function definition time kills the need for the usage of let when defining closures inside loops (you can just pas the value you want to capture in a closure as the default value of a param) or other things like that.
- hk__2 9y ago> I'd be more inclined to [s]ay that let mostly encourages you to write zillion-line functions (instead of lots of small ones), simply because with it you "mentally can" since you can see the scope of variables better. That’s true. I revise my comment as "Any piece of code that uses a variable[ to hold something you use multiple times and don’t want to recompute]."; for example creating an API client then using it twice.
- yoodenvranx 9y ago> Hy This must be the worst submission title in the history of HN.
- asimjalis 9y agoIt is possibly the shortest.
- hk__2 9y agoI got curious and I checked; there have been a few one-character submissions so it’s not the shortest. ⊥: https://news.ycombinator.com/item?id=7530548 {: https://news.ycombinator.com/item?id=7729399 M: https://news.ycombinator.com/item?id=4367006 In total (at least in the [fh-bigquery:hackernews.stories] BQ dataset), there have been 15 non-deleted submissions with a one-character title.
- winter_blue 9y agoSince Python doesn't support multi-line lambdas, how do they support the analog in LISP? It's almost necessary for any dialect of LISP to support lambdas (i.e. functions) that contain a LISP 'do' [1] which lets you group statements. Do they chain together expressions/statements with continuations or something? [1] http://www.lispworks.com/documentation/lw60/CLHS/Body/m_do_do.htm http://www.lispworks.com/documentation/lw60/CLHS/Body/m_do_d...
- gkya 9y agoIIRC in a talk the author said that it just generated a function with a made-up unique name, like an internal def in another function.
- serhei 9y agoThat's pretty similar to how languages like Scala with higher-order features translate down to the JVM bytecode (which is subject to certain restrictions).
- kazinator 9y agoIn general, if some target language entity exists in a named form only, then the corresponding anonymity of those entities in the source language must be simulated via gensyms. For instance, the branch targets in a while loop are anonymous, right? But in the target language, you must have a named label for the instruction. Solution: machine-generated label.
- joejev 9y agoPython lambdas are just syntactic sugar for creating a function object. The ast can just build a named function and use it in the needed expression.
- kazinator 9y agoHowever, that approach seems rather backwards compared to having an anonymous function primitive which is used as the basis for the lambda one-line-only sugar, as well as named functions (which simply establish a binding between a name and the anonymous thing).
- tills13 9y agohy more like why
- etiam 9y agoThere's even a couple of kernels for IPython/Jupyter. The best I've seen so far is https://github.com/Calysto/calysto_hy https://github.com/Calysto/calysto_hy I'd like to move to Hy for much more of what I currently do in Python, but so far I've been too lazy to find/create good editor support for it. For actual projects of some size the loss of context help, documentation, various completions, etc seems like too high a price to pay.
- zitterbewegung 9y agoI think the highest cost is really collaboration with others. If you ever want help with your project or if people even want to use it you are dealing with only Hy users and disregarding regular Python users. I do like the concept of Hy though.
- etiam 9y agoIt's restrictive that way, no doubt. On the other hand, I suspect that as subsets go, Hy programmers would be a good one. And I'm not sure the impact on getting people to use it would necessarily be that bad. It's just an extra import hy away to use modules written in Hy just as usual from Python, after all.
- thro1237 9y agoAlso, in terms of useful debug/error messages. That was the biggest drawback of clojure.
- partingshots 9y agoNow CS61A can finally go back to teaching purely in Scheme again.
- kronos29296 9y agoThe entire thing is full of puns really too much of puns related to hy. Cool project. Python joined Erlang and Java with a lisp flavour of its own with Hy. Hope we get a let expression soon.
- smaili 9y agoExcerpt: > Hy is a wonderful dialect of Lisp that's embedded in Python. > Since Hy transforms its Lisp code into the Python Abstract Syntax Tree, you have the whole beautiful world of Python at your fingertips, in Lisp form!
- dvdt 9y agoOne fun application: I used Hy to control my liquid handling robot, https://twitter.com/dtsao/status/891038101706989568 https://twitter.com/dtsao/status/891038101706989568
- cuspycode 9y agoI used Hylang to program an Arduino Yún a few years ago, via cross-compilation. This was a very nice experience, since it allowed me to use the great Python ecosystem without having to be limited by Python the language.
- udkl 9y agoWhile both have their own personalities, has anyone done a side by side syntax and feature comparison of clojure and Hy ?
- ealhad 9y ago“Keep in mind we’re not Clojure. We’re not Common Lisp. We’re Homoiconic Python, with extra bits that make sense.” — Hy Style Guide That said, Hy takes a lot from Clojure.
- flavio81 9y ago> That said, Hy takes a lot from Clojure. Oh oh... That scares me. Clojure -as a Lisp-like language running on the JVM- is a good idea but i have some reservations regarding how that idea got implemented.
- ealhad 9y agoI can only agree with you. I don't like some of the syntactic choices of Clojure, and sadly some of those are in Hy.
- didibus 9y agoFeatures are very different, because the features of Hy are the features of Python. So any comparison of Clojure vs Python will do. The syntax though is very similar.
- IgorPartola 9y agoAs a heavy user of Python, and someone who grew up with the "curly braces" languages, I have a question for y'all. Is this really readable? (setv result (- (/ (+ 1 3 88) 2) 8)) Or rather is it more readable than result = ((1 + 3 + 88) / 2) - 8 I just... Do you just get used to this, or is it something that you have to keep struggling with? Especially given that the latter is how we do math the rest of the time?
- evilduck 9y agoIt's just training. Buy and use a RPN calculator and lisp suddenly seems normal. (To answer your question directly, yes it's readable. You learn to look past the syntax in lisp the same as you stop reading semi-colons and curly braces in other languages)
- deleted 9y ago[deleted]
- gkya 9y agoM-x calc!
- xelxebar 9y agoOr if you're a fan of cli tools, check out dc!
- unkown-unknowns 9y agoI use dc every now and then but I wish it'd do decimal math by default. 9 35 5 12 *+/p Furthermore I think it's strange that the order of the operands of the division operator is divisor as top-most value on the stack and dividend as second top-most value and not the other way around. For example, to me it'd feel more natural if 3 5 /p was equivalent to 5 / 3 in infix notation, not 3 / 5 Because when I think of a fraction I think of it as "dividend over divisor". Edit: Actually I Googled and it makes sense now. I've been focusing on what's on the stack but if we look at what is provided as input instead then it becomes "calculate dividend, calculate divisor, divide". Longer example which shows this: Algebraic expression (4 + 2 * 5) / (1 + 3 * 2) RPN 4 2 5 * + 1 3 2 * + /
- evanwolf 9y agoNext on the wishlist: an APL inside Python.
- wodenokoto 9y agoWill this give me lisp in jupyther notebooks?
- mmaul 9y agoYou can already have lisp (common) in jupyter notebooks via cl-jupyter. Here is an example https://github.com/mmaul/clml.tutorials/blob/master/CLML-Wine-pca-k-means-and-hierarchical-clustering.ipynb https://github.com/mmaul/clml.tutorials/blob/master/CLML-Win... If you want to use Hy in a note book you will need a jupyter kernel for it and I belive there is one called hy_kernel
- amelius 9y agoIs this like clojure, but for python instead of java?
- kirbyfan64sos 9y agoYup, although Hy tries to stay much closer to Python's semantics than Clojure to Java's.
- gcoda 9y agoReason I am trying it - best "hello world" example ever. (print "I was going to code in Python syntax, but then I got Hy.")
- eanzenberg 9y ago((1 + 3 + 88) / 2) - 8 is unreadable? Can I have some of the crack you're smoking?
- Goopplesoft 9y ago> equally (un)readable Means they're the same to them regardless of whether its readable or not (they aren't even opining here).
- sctb 9y agoCould you please not do this here? We detached this subthread from https://news.ycombinator.com/item?id=14914448 https://news.ycombinator.com/item?id=14914448 and marked it off-topic.
- souenzzo 9y agoSee also https://github.com/pixie-lang/pixie https://github.com/pixie-lang/pixie
- nerdponx 9y agoI wanted to get into Pixie but last I heard it was a dead project.
- souenzzo 9y agoIt's not "dead" https://www.youtube.com/watch?v=1AjhFZVfB9c https://www.youtube.com/watch?v=1AjhFZVfB9c It's a weekend project, for fun. Functions that are work will not stop to work. I'm using it and I pretend to contribute when I find a problem.
- nerdponx 9y agoGreat to hear. I'm still not sold on CL as "my Lisp of choice", so I would be happy to give Pixie a shot.
- macdice 9y agoInteresting that it uses defun, like Common Lisp, the main Lisp-2 dialect, and yet it's clearly a Lisp-1, like Scheme. After (defun f (n) (+ n 1)), evaluating f shows that it's a function (just as in Python, which is a Lisp-1). My first thought, for what it's worth, is that if the namespace semantics is like Scheme it'd be better to follow Scheme idioms rather than Common Lisp, so code can be easily ported. On the other hand, this is only my first minute using Hy so what do I know. Looks really neat!
- kazinator 9y agoEuLisp (pretty much defunct) is also a Lisp-1 dialect with defun.
- droidist2 9y agoHow does this work with tooling though, like step debugging and refactoring in IDEs like PyCharm, or with iPython notebooks?
- dmoney 9y agoUnicode identifiers make me uncomfortable. I have no idea how I would type that circular one in the "sharp macro" section (short of copying and pasting), and I'm imagining seeing those missing-character boxes all over the place.
- yorwba 9y agoI think that example was more tongue-in-cheek than anything (after all, who would want to write their code in reverse). But if you use e.g. the fcitx input on Linux, you can just press Ctrl-Alt-Shift-U, type "circle arrow", and select "↻" (clockwise open circle arrow) from the list. The fuzzy matching is pretty awesome, I hope similar Unicode handling will come to all platforms in the future.
- robobro 9y agoHas anyone ever used Hy for CGI stuff? It may be possible to port Hackernews to it, just for fun..
- sridca 9y agoA decade ago I wrote something like this using Racket (formerly MzScheme)! https://github.com/srid/boalisp https://github.com/srid/boalisp
- yablak 9y agoAs a tensorflow dev, with several years experience writing clojure at a previous startup, I believe this is the most natural language for writing tensorflow models (or theano. basically any graph building dsl that has any real complexity and has been bolted onto python). Suddenly TF's cond and while_loop and context controls all fit naturally into the language. My favorite technical post in recent memory.
- yablak 9y agoAs a tensorflow dev, with several years experience writing clojure at a previous startup, I believe this is the most natural language for writing tensorflow models (or theano. basically any graph building dsl that has any real complexity and has been bolted onto python). Suddenly TF's cond and while_loop and context controls all fit naturally into the language. My favorite technical post in recent memory.