I'm really glad we're starting to see compile-to-Python languages crop up. Don't get me wrong, Python is a great language, and the community around it is fantastic, but it's missing key functional/concurrency features that would make certain problems much less tedious to solve. For instance, I love the built-in use of persistent data structures in Mochi--that's something that's sorely missing from the Python standard library.
Hy aims to be bidirectional. Swapping around data structures will mess with that. Hy doesn't want to be intrusive, you should really be able to tell when you use Hy code.
Super cool stuff. I'm a fan of statically typed languages as a rule, but do python at my job, so this is very relevant to me. I've long thought there should be (and have half-assedly attempted to make) a simple, python-like dynamically typed language which supports functional staples such as pattern matching, expression syntax (i.e. no need for explicit return), records and the like. And it has persistent data structures, which are (inexplicably) still missing from python after all these years. Bravo!
The one thing I didn't see, though: lambdas? Is it python syntax for those? Is there support for pattern matching inside of lambdas?
You should take a look at Julia. It does not have pattern matching, but it does have multiple dispatch and pretty much every other functional programming staple. I don't know about persistent data structures but someone may have already done it, or it could be done with macros.
Where in my post did I suggest otherwise? I realize I didn't word it the clearest way but I don't think I ever indicated that python was anything but dynamically typed. To be clearer:
* I prefer statically typed languages as a rule
* However, I do python at my job (which is not statically typed)
* there are many features which tend to be found in statically typed functional languages, which I would love to see in a dynamically typed, python-like language.
I don't think off-side rule languages get enough credit; python probably has the best syntax aesthetics of any language out there. I like how the author realized a bunch of interesting features (pattern matching) with this syntax.
I'm on mobile, so can't easily find a link. But its basically the term landen used to describe using indentation to delimit block structure. There is a wiki page on it.
http://dl.acm.org/citation.cfm?doid=365230.365257 and gratis copies elsewhere; required reading since 1966. Of course "off-side" is a football term, somewhat significant in England later that year.
However, Python doesn't use Landin's off-side rule; colons are required, c.f. Haskell's usual syntax. Emacs works anyhow.
I prefer Python's use of colons to haskell's nothingness. Now...that means colons can't be used for types or cons, but it makes a lot of sense for python.
Ok, I figured as much. I've only ever seen 'significant whitespace' to describe this, but I guess that's not very clear either. I myself do like it as well, I just wish tabs were the default for indenting in editors and general best practices instead of spaces.
The pattern-matching, actors, and pipeline operator seem like they were inspired by Elixir. Was that a conscious source of ideas or just stuff you came across elsewhere and thought was good?
Isn't actor-style programming a bit problematic when your interpreter has a GIL ? Aren't actor supposed to be executed in parallel for maximum performance ?
it is using eventlet in the background, so for IO-bound tasks you will see concurrency, but I would imagine that CPU-bound tasks will still be hampered by the GIL in the same way that vanilla Python is.
This looks fantastic. Python always feels like it's almost as good as a dynamic, imperative language could get, but I miss some of the functional idioms from other languages. It's great that this is just a thin layer over Python too, so it can hook into the ecosystem, and it's a realistically sized project for a single developer to maintain.
It's written and supports python fully (see flask snippet and source). The code was definitely an interesting read. Really cool and well done OP.
My only gripe is that unfortunately the reverse isn't true (you can't 'mochi' in python). I wonder how much could be achieved with a 'Dynamic functional programming for humans' type thing that stays pure python.
It compiles to AST, so he could just do the same we did in Hy, write a import hook and stuff the compiled AST back as an module. Then python should be able to use mochi without many limitations.
Ruby is already very DSL friendly so writing something on top of it that at the end of the day just compiles down to Ruby does not provide the same kind of power/effort ratio as in the Python case. Plus there's already elixir which covers similar territory.
True. But being able to use something like actors or functional constructs, immutable data structures etc from within rails for example, could be neat. If it's baked into the language this way it enforces those ideas better. Using elixir could be great but it's a much bigger jump from the ruby ecosystem.
Coffeescript is a transpiler. It converts its own code directly into javascript code. This project converts its code to AST, not Python code itself. You can generate the Python code off from the AST, but it dosnt always imply the resulting Python code is runable.
> You can generate the Python code off from the AST, but it dosnt always imply the resulting Python code is runable.
I believe this is incorrect. Can you show an example of a valid abstract syntax tree that could not be represented in the grammar of the original language?
I know that variable names in Python's AST can be any string, so for instance you could declare and use a variable named "+a-b$ $$?", even though that's not valid Python code. That's pretty minor, though, so I'm curious if there's anything more significant.
We got this very "problem" in Hy. AST allows for several characters as Names, where python does not.
A great example is with gensym, here we will make an ast.Name node with a prefix ":", if you run astor over this, you produce AST containing that very character. What happens if you try run this Python code? Syntax error. There is also a few other cases i can't think off right now.
This looks a lot like Elixir to me, which is exciting. Elixir has great ideas, but Python has much more in the way of ecosystem and libraries. It's an appealing idea to have pattern matching and concurrency on top of the libraries I take for granted.
Even the macros look very similar. Surely this has drawn inspiration from Elixir.
Sorry, that wasn't meant to read as sarcastic or critical, I actually think Mochi is really neat. I love Scala, basically because it adds pattern matching to Java, and am really happy to see Python get a similar treatment.