6 ms·
Try Hy
- ninetax 13y agoIt's a dialect of LISP that's compiled down to Python AST IICR. Here's more information: http://docs.hylang.org/en/latest/tutorial.html http://docs.hylang.org/en/latest/tutorial.html
- vezzy-fnord 13y agoNot bad. Could be a very useful tool to teach Python programmers Lisp, although I don't think Python benefits much from converting its syntax to sexprs.
- nine_k 13y agoIf this thing supports macros (and it seems to, see the pipe example in the tutorial), it may be more powerful than Python — as you'd expect from a Lisp.
- agentultra 13y agoIt supports macros. It's a lisp-1 and they're not hygienic... but you can hack away with them.
- aidenn0 13y agoand symbols are just strings... that makes writing macros nearly impossible. CL doesn't need hygenic macros since two symbols with the same name from different packages are not the same it's hard to accidentally shadow someone else's definitions. P.S. The lisp-1 nature of scheme isn't why hygenic macros are important there, it's really a bit of a red-herring, since macros in common-lisp can (and do) use (flet) and (labels)
- agentultra 13y agoI wouldn't say it's impossible but one should be aware of the issues. And we can always use more contributors to help make it better. Hy isn't trying to be CL or Scheme. It is still after all, Python. However a homoiconic front-end to Python has interesting implications for a language like Python. Macros in Hy are almost like a template language for Python ASTs. You could replace the namedtuple implementation with a Hy macro. If Python didn't have a `with` keyword you could implement it as a Hy macro. I'm sure there may be more. Python's not a lisp under the hood. However it does benefit from some of the superficial features of a homoiconic transpilation. :) </cheeky>
- mkramlich 13y agoA+ for presentation
- nick2021 13y ago(-40 1) = 40. To be honest this is a stupid syntax. Basically it reads 40 - 1 from what I can tell from playing around. Why would you take -40, something that everyone understands as negative forty and make it mean forty minus?
- ravestar 13y ago[]+1 = [] 1 []+[] -> error ...
- twotwotwo 13y agoIt's using prefix notation, so => (+ [] []) [] As in Lisp, commas aren't needed to separate list items. []+1 is parsed like [] followed by positive 1 (+1), which is why it ends up executing even though it's infix notation passed into a prefix-notation parser.
- ravestar 13y agoWAT. I entered 3 items to input: [] + and 1 - this it is evaluated without error, but was expecting ([] + 1) or something as a result or error. Why there is no error? Why symbol + and a number are evaluated like + was an operator?
- twotwotwo 13y agoThe + in +1 is bound tightly to the number like the - in -1. Think of it as meaning "positive," not addition. Also, Hy's lexing appears to have an interesting feature where you don't always need a space to delimit things, so []+1 is automagically broken up into [] and +1. Here are some other examples where it breaks things up: => []"foo"3"hey"["wakka""wakka"] [] u'foo' 3 u'hey' [u'wakka', u'wakka'] => (+[1][2][3]) [1, 2, 3] So without parens, []+1 is like []; +1; in Python and prints out the same result. With parens, the first token of ([]+1) is treated as a function (as would be typical in Lisp) so it tries to execute the Python [](+1), and you get the error that [] isn't callable. So []+1 ran, but not for the obvious reasons. I'm basically poking at the REPL like you to try and puzzle this out; if you want to dig further, you could look at Hy's docs or source or contact the folks that wrote it. Edit: an additional detail, not sure if it's informative or just confusing-- "+ 1" is apparently lexed by Hy as two items, not as positive 1: => [] + 1 [] Traceback (most recent call last): File "<input>", line 1, in <module> NameError: name '+' is not defined
- anaphor 13y agoSo it just desugars into Python? I see there is a section in the documentation for macros, but there's nothing there. Does it support AST macros right now? I thought of doing something similar to this except doing some kind of static or gradual typing (that would be a larger project though).
- Foxboron 13y agoIt desugars into python's AST, not python.
- haney 13y agoI've had similar ideas. I really like the batteries that are included with python but I would like to be able to add type annotations that are enforced to my code base for type safety. I also really like the idea of being able to extend the language with macros. Hy certainly seems like a good start towards a language like this.
- anaphor 13y agoI think the problem with adding even gradual typing to Python is how to handle duck typing. A lot of existing Python code relies on implicit assumptions about the parameters of functions, e.g. "this is an iterable" or "this is a number or supports some numeric operations". I know there are some Python libraries that formalize interfaces like this, but I can't see a good way of doing it nicely in general and being able to calculate the types of everything (with or without explicit annotations). Someone can correct me if I'm wrong but I don't think Scala or Clojure code has this problem.
- haney 13y agoI hadn't thought about the duck typing issue. What I have in my mind is more akin to contract programming. I'd love to take a look at a library that does this. I just hacked something together during my layover to give it a try.
- toxik 13y agoThere is something called "abstract base classes" which provide the sort of interface testing you're asking for. You can, in Python, see if a thing supports (or more precisely claims to support) item access, iteration, sequence behavior, etc.
- jackhammons 13y agoIncredible implementation.
- deleted 13y ago[deleted]
- agentultra 13y agoI did a little presentation on Hy at Pycon Canada earlier this year [1]. Hy has come a ways since then even. Shortly after that talk we added succinct syntax aliases for QUOTE and QUASIQUOTE. And we added a nice clojure-inspired core library. It's a cool little language. Fun to hack on. You could learn a few things if you do. And I do hope that we can start help creating documentation for the Python AST module via this project. [1] http://pyvideo.org/video/2328/hy-a-lisp-that-compiles-to-python http://pyvideo.org/video/2328/hy-a-lisp-that-compiles-to-pyt...
- hcarvalhoalves 13y agoExcellent. I thought what a LISP on top of the Python runtime would be (like Clojure + JVM), didn't knew this existed already.
- nlake44 13y agoSource: https://github.com/hylang/tryhy https://github.com/hylang/tryhy
- paultag 13y agoWell done! If anyone wants to learn more: http://hylang.org/ http://hylang.org/ http://github.com/hylang http://github.com/hylang http://www.youtube.com/watch?v=ulekCWvDFVI http://www.youtube.com/watch?v=ulekCWvDFVI and a quick 5 minute lightning talk: http://youtu.be/1vui-LupKJI?t=16m13s http://youtu.be/1vui-LupKJI?t=16m13s (Creator here) Hack on!
- kro0ub 13y agoGreat work, man.
- jbeja 13y agoIs Python really that awesome?
- d0m 13y agoI think this is fucking amazing.
- talles 13y agoLove at first sight with the presentation
- mattholtom 13y agoHeh, recognized reverse polish notation right away. One of the companies I interviewed at last year had me program an RPN calculator fed by CSV spreadsheets. Weirdest thing I've made to date by a pretty wide margin.
- sockgrant 13y agoThey had you do that in the interview?
- mattholtom 13y agoHeh, no. It was as a take home coding project (in my earlier and dumber years, I would never do this now). This was after one business and two technical phone screeners. Then after they reviewed my code, I was brought in for a marathon interview lasting from 9:30AM to 6:30PM on a Friday. I left for a wedding when they started their company wide "pizza and demo night". I imagine after this was done they pulled out cots and handed out stuffed animals and blankies to the bro's. In the end, I was so massively frustrated that I forced myself to nail everything they threw at me just so I could have the satisfaction of turning down their job offer, which I did. Thanks matchu for the additional info on RPN. I didn't know about the stack evaluation benefit, that is very cool.
- matchu 13y ago"+ 41 1" more closely resembeles straight-up non-reverse Polish notation. Its cool property is that it has unambiguous grouping without parentheses. Reverse Polish notation's even cooler property is that, in addition to the unambiguity, it can easily be evaluated from left to right with a stack: If you see a operand, push it onto the stack. If you see an operator, pop two operands off the stack, compute, and push the result onto the stack. By the end you'll have a one-element stack with your result. Really what we're seeing here, though, is a language without infix operators: all functions are of the form "<name> <operand1> <operand2>…", but grouping still works as expected. http://en.wikipedia.org/wiki/Polish_notation http://en.wikipedia.org/wiki/Polish_notation http://en.wikipedia.org/wiki/Reverse_Polish_notation http://en.wikipedia.org/wiki/Reverse_Polish_notation
- Sunlis 13y agoFinally my knowledge of Scheme comes in handy!
- basyt 13y agoeffin' finally. now to do some serious lisping!
- jbeja 13y agoThis could be the next big thing.
- derp_dogg 13y agowhere's cons?
- skrebbel 13y agoIt only has pros.
- derp_dogg 13y ago+ is overloaded (+ '(1 2) '(3)) => '(1 2 3)
- danneu 13y agohttps://github.com/danneu/hyclops/blob/master/hyclops.hy#L275-L281 https://github.com/danneu/hyclops/blob/master/hyclops.hy#L27... Some hilariously bad implementations in that file, but it's just for fun.
- dmoney 13y agoTo quote Dark Helmet, "What the hell am I looking at?"
- girvo 13y agoHy is neat. I love Lisps that "compile" or are embedable within host scripting languages. My favourite one to hack on (owing to my PHP ability) is Pharen[0]. Very neat little Lisp that compiles down to PHP, which is very fun to play with. I highly suggest giving Hy a go if you're a Pythonista, as you can learn a lot about programming in general by seeing how these sorts of languages map to the host. Very fun to hack on, too! [0]: http://scriptor.github.io/pharen/ http://scriptor.github.io/pharen/
- zaph0d 13y agoVery nice. Surface syntax (and some semantics like interop) seem to be heavily inspired by Clojure :-)
- a3_nm 13y ago"(defun f x (x))" gives a Python stack trace.
- chrismonsanto 13y ago(defun f (x) (x))
- a3_nm 13y agoYes, I wasn't expecting this wrong syntax to work, just pointing out that the stack trace looks messy (e.g., leaks the absolute path to the involved Python file).
- dagurp 13y ago(defun f [x] (x))
- petercooper 13y agoWhat blew my mind is this actually worked on my iPod Touch and brought up the keyboard. Usually "dynamic" JavaScript keyboards or games totally fail on there..
- andrelaszlo 13y agoApparently without TCO :( File "<input>", line 1, in fac File "<input>", line 1, in fac File "<input>", line 1, in fac RuntimeError: maximum recursion depth exceeded =>