

Python Can Now Call Code Written in Chris Lattner's Mojo (modular.com) 26
Mojo (the programming language) reached a milestone today.
The story so far... Chris Lattner created the Swift programming language (and answered questions from Slashdot readers in 2017 on his way to new jobs at Tesla, Google, and SiFive). But in 2023, he'd created a new programming language called Mojo — a superset of Python with added functionality for high performance code that takes advantage of modern accelerators — as part of his work at AI infrastructure company Modular.AI.
And today Modular's product manager Brad Larson announced Python users can now call Mojo code from Python. (Watch for it in Mojo's latest nightly builds...) The Python interoperability section of the Mojo manual has been expanded and now includes a dedicated document on calling Mojo from Python. We've also added a couple of new examples to the modular GitHub repository: a "hello world" that shows how to round-trip from Python to Mojo and back, and one that shows how even Mojo code that uses the GPU can be called from Python. This is usable through any of the ways of installing MAX [their Modular Accelerated Xecution platform, an integrated suite of AI compute tools] and the Mojo compiler: via pip install modular / pip install max, or with Conda via Magic / Pixi.
One of our goals has been the progressive introduction of MAX and Mojo into the massive Python codebases out in the world today. We feel that enabling selective migration of performance bottlenecks in Python code to fast Mojo (especially Mojo running on accelerators) will unlock entirely new applications. I'm really excited for how this will expand the reach of the Mojo code many of you have been writing...
It has taken months of deep technical work to get to this point, and this is just the first step in the roll-out of this new language feature. I strongly recommend reading the list of current known limitations to understand what may not work just yet, both to avoid potential frustration and to prevent the filing of duplicate issues for known areas that we're working on.
"We are really interested in what you'll build with this new functionality, as well as hearing your feedback about how this could be made even better," the post concludes.
Mojo's licensing makes it free on any device, for any research, hobby or learning project, as well as on x86 or ARM CPUs or NVIDIA GPU.
The story so far... Chris Lattner created the Swift programming language (and answered questions from Slashdot readers in 2017 on his way to new jobs at Tesla, Google, and SiFive). But in 2023, he'd created a new programming language called Mojo — a superset of Python with added functionality for high performance code that takes advantage of modern accelerators — as part of his work at AI infrastructure company Modular.AI.
And today Modular's product manager Brad Larson announced Python users can now call Mojo code from Python. (Watch for it in Mojo's latest nightly builds...) The Python interoperability section of the Mojo manual has been expanded and now includes a dedicated document on calling Mojo from Python. We've also added a couple of new examples to the modular GitHub repository: a "hello world" that shows how to round-trip from Python to Mojo and back, and one that shows how even Mojo code that uses the GPU can be called from Python. This is usable through any of the ways of installing MAX [their Modular Accelerated Xecution platform, an integrated suite of AI compute tools] and the Mojo compiler: via pip install modular / pip install max, or with Conda via Magic / Pixi.
One of our goals has been the progressive introduction of MAX and Mojo into the massive Python codebases out in the world today. We feel that enabling selective migration of performance bottlenecks in Python code to fast Mojo (especially Mojo running on accelerators) will unlock entirely new applications. I'm really excited for how this will expand the reach of the Mojo code many of you have been writing...
It has taken months of deep technical work to get to this point, and this is just the first step in the roll-out of this new language feature. I strongly recommend reading the list of current known limitations to understand what may not work just yet, both to avoid potential frustration and to prevent the filing of duplicate issues for known areas that we're working on.
"We are really interested in what you'll build with this new functionality, as well as hearing your feedback about how this could be made even better," the post concludes.
Mojo's licensing makes it free on any device, for any research, hobby or learning project, as well as on x86 or ARM CPUs or NVIDIA GPU.
Is there nothing Chris cant do? (Score:3, Funny)
First he he destroys Kentucky with that buzzer beater, goes on to win March Madness with Duke, and now write an entire programming language? Whew!
Re: (Score:2, Funny)
wtf (Score:1)
When I'm going for performance I always choose an interpreted language. Yes, please throw in an ecosystem that is a security nightmare. I feel like vibe-coding this thing.
Re: (Score:1)
Even when compiled, Python is a dog. VB6, with its 30-year-old compiler, beats the pants off of CPU-bound Python. Like by a factor of 4, even with all the bells-and-whistles Python libraries (which are NOT written in Python, mind you, so the handicap even goes to VB6's disadvantage). And, yes, I've done the legwork, implementing the same 20-odd thousand line functionality in both. VB6 is a horrid language, broken and impoverished. But, then, so is Python, with it's pervasive inconsistencies, fragility,
Re:wtf (Score:4, Funny)
who in their right mind would implement normal loop termination by raising an exception?
Terminating your loops is a sign of weakness.
Quickly turning into C++ (Score:2)
def repeat[count: Int](msg: String):
@parameter
Re: (Score:1)
Re:Quickly turning into C++ (Score:5, Insightful)
So yeah, go take a math class or something so you learn to recognize elegance. Once you recognize it, you'll soon start to produce it.
Re: (Score:2)
As a hardware developer who only dabbles in programming, I've never really understood the reason for "elegant" code. I mostly find it hard to read and understand.
To me, good code is self-explanatory and, barring that, well documented. It should also produce an efficient program, but that's not *necessarily* directly linked to what I've seen programmers call "elegant", which is usually something much shorter and more cryptic than I would have written. With no comments, of course.
Re: (Score:2)
You are generally correct. Maintainability is the most important aspect of code, not lines of code nor cleverness for clever's sake.
While the writer might initially find something "elegant" easy to read, it's often not safe to extrapolate this to other dev's or yourself 5 years down the road when you've forgot why you did what.
Re: (Score:2)
Re: (Score:1)
The boundary is fuzzy, or at least many mistake one for the other because they don't or can't consider how others will interpret their code (often due to inexperience).
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
what I've seen programmers call "elegant",
Most programmers can't recognize elegance if they see it.
As a hardware developer who only dabbles in programming, I've never really understood the reason for "elegant" code
Ok, so you don't recognize elegance either.
To get a hint, consider this quote (although it has nothing to do with geniuses, it's just people who've developed that skill):
Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it. --Alan Perlis
Re: (Score:2)
>Ok, so you don't recognize elegance either.
I would never presume to recognize it.
It's just that all the examples I've seen of supposed elegance in code have seemed more like inside jokes between people in the know. Or possibly a way to increase job security... as long as nobody can understand WTF you did without immense effort, you're more difficult to replace. Yay?
>Quoting a high end philosopher with an incomprehensible unrelated quote makes your argument unassailable by small minds.
I love it. Defin
Re: (Score:2)
It's just that all the examples I've seen of supposed elegance in code have seemed more like inside jokes between people in the know.
You keep describing things that are clearly not elegant.
Re: (Score:2)
Exactly. I'm describing things programmers THINK are elegant.
Re: (Score:2)
Re: (Score:1)
If one's going to code like that, might as well use C# or Java and get the full power of compiler checking.
However, I do like the type indicator coming after the variable, as Pascal did. It made sense in the original C because type-names were short back then.
Re: (Score:1)
Clarification: The type indicator coming first made more sense in early C, when type indicators were short and simple.
Re: (Score:2)
If one's going to code like that, might as well use C# or Java and get the full power of compiler checking.
Not to mention an IDE that can operate without AI.
Swift (Score:4, Interesting)
It replaced Objective C (which had all the warts from C) with a language that had all the warts from C and Objective C and from Swift. Storing values in recursive enums is just a plain dumb language feature.
Just what the world needs (Score:3)
It's millionth computer language.