Back to the talks Previous by track: p-search: a local search engine in Emacs Next by track: Beguiling Emacs: Guile-Emacs relaunched! Track: Development

Exploring shared philosophies in Julia and Emacs

Gabriele Bozzola (he/him/his) - GitHub: @sbozzolo Website: https://sbozzolo.github.io LinkedIn: gabrielebozzola

Format: 10-min talk ; Q&A: BigBlueButton conference room
Status: TO_CAPTION_QA

Talk

Duration: 09:17 minutes

Q&A

00:00.089 Q: Do you have any suggestions for interactive debugging of Julia code in Emacs? 01:08.286 Q: Can you call out something that Julia has that Emacs does not, and which could benefit Emacs? 02:36.797 Q: Is there a way to use lisp syntax with Julia, like hy for python or lisp flavoured erlang? 03:51.168 Q: Have you tried the Julia Snail package for Emacs? It tries to be like SLY/SLIME for Common Lisp. 04:22.940 Q: Is there a data inspector for a Julia REPL available that you can use in Emacs? 05:24.443 Q: Have you tried literate programming Julia (using Org babel or some other means) in Emacs?

Listen to just the audio:

Description

While seemingly disparate, the Julia programming language and Emacs share a surprising kinship. This talk delves into the common design principles and philosophies that unite these powerful tools, focusing on their shared emphasis on extensibility, customization, and interactive development. I'll explore how both Julia and Emacs empower users to tailor their experience through powerful metaprogramming and a rich ecosystem of extensions. I'll discuss the REPL-driven workflows that foster exploration and experimentation in both environments. Furthermore, I'll examine how their active and passionate communities drive innovation.

Discussion

Questions and answers

  • Q: As someone who uses Julia, Emacs and Julia in Emacs, I feel like Julia's integration with Emacs is lacking.  I haven't found any way to debug Julia code that works as well as edebug for elisp, SLY/SLIME for common lisp, or gdb for many other languages (with gud or realgud).  Both Debugger.jl and Infiltrator.jl are difficult to use interactively. Do you have any suggestions for interactive debugging of Julia code in Emacs? (Adding to my question: Do other editors do a better job of interactive Julia debugging?)
    • A: GB: Debbuger.jl and Infiltrator.jl are the main debugging tools available in Julia at the moment. Both of them are not great (yet) and can use some work. Debugger is going to see major performance improvements in future releases thanks to work in the core language. Unfortunately, I don't see anything better for interactive debugging that is avilable now or in the near future. Most of the julia community is clustered around VS code, but the situation is not better
  • Q: Can you call out something that Julia has that Emacs does not, and which could benefit Emacs?
    • A: GB: The Julia community is active and more tightly knit than other communities (e.g., the Python one), JuliaCon is an in-person event that brings people together. Emacs is also doing great in this.
  • Q: Is there a way to use lisp syntax with Julia, like hy for python or lisp flavoured erlang?
    • A: Julia used to have a femtolisp interpreter built-into its REPL.
    • A: GB: I am not aware, but it might be possible to write a package to do that.
  • Q: Have you tried the Julia Snail package for Emacs?  It tries to be like SLY/SLIME for Common Lisp.
    • A: GB: Yes, but I settled on julia-repl (with vterm). I didn't test julia-snail too much because I found julia-repl easier to setup and use the way I wished.
  • Q: Along the same lines as question 1 -- is there a data inspector for a Julia REPL available that you can use in Emacs?
    • A: good mode, other good tooling; room for improvement in this area
    • A: GB: No, I don't think anything of that sort is available 
  • Q: Have you tried literate programming Julia (using Org babel or some other means) in Emacs?
    • A: Literate programming in Julia: Pluto (Jupyter-style, in the browser), emacs-jupyter (in Emacs)

Notes

  • Great, now I wanna learn Julia... :-)
    • Highly recommend it. Especially if you do any sort of scientific computing. It's an amazing language
  • Lots of things to like. Perhaps the most Dylan-like modern language? 
  • Got me interested in Julia, great talk
  • Sooooo emacs written in julia?
  • Amazing, thank you
  • M-x clap
  • Great talk [13:10]
  • Thank you for the talk! \o/
  • Thank you!
  • I've been so happy ditching python for julia for all my scientific research needs :)
  • Some of these features, like the interactivity and the decompiler reminds of Common Lisp
  • One of Julia's best features (multiple dispatch) was inspired by Common Lisp's defgeneric/defmethod.
    • I would also add that Julia takes the idea further than Common Lisp ever did, because you can't opt-out of being generic in Julia, so it's everywhere and used pervasively.
    • In Common Lisp, you had to opt-in, so it wasn't as apparent how powerful this way of organizing code could be.
  • Got me interested in Julia, great talk
  • Sooooo emacs written in julia?
  • akirakyle: First Guile Scheme (re: Robin's talk, next), then Julia! ;-)
  • Yes ;)
  • So julia is like using CLOS everywhere?
  • Sort of, but with the llvm runnig full optimized native code generation for every argument type a function is called with
  • also julia --lisp is built in!
  • emacs-jupyter works with julia quite well btw
  • org-babel also works well
  • def looking forward to the julia talk
  • It would be great to integrate pluto with emacs, but currently very hard to figure out best way to do so
  • That would be interesting for sure
  • Pluto.run(auto_reload_from_file=true) is the best right now
    • Problem is pluto is very tied to browser
    • I dislike leaving emacs for things
    • But Pluto is a great tool
    • Same, I suppose one could alternatively say the problem is emacs can't be very easily tied to the browser
    • As opposed to vscode where such integrations are easier
    • Although, on the other hand, I am happy emacs isn't tied to a browser
    • It's better in general
    • Yes it shouldn't be tied to a browser, but it also would be very helpful for emacs to have better access to rendering content that requires a dom/js environment in an emacs window

Transcript

Hello, I'm very excited to tell you about shared philosophies between the Julia programming language and Emacs. While Julia and Emacs might look like different pieces of software, I think there is profound commonalities between the two. Let's start by introducing Julia. Julia is a high-level dynamic programming language. Julia is free and open source software and is used primarily for scientific computing. The reason Julia is used for scientific computing is that while Julia is high level and has a syntax that looks like Python or MATLAB, Julia can be high performance. I use it to develop climate models that run on hundreds of GPUs. Models that are traditionally developed with C, C++, or Fortran. But how is this possible? How can Julia be high performance but also high level at the same time? What makes Julia, Julia? Well, what makes Julia, Julia is the idea of multiple dispatch. Multiple dispatch is the concept where a function call is resolved by looking at the types of every single argument involved. So, let's explore this with this example. Here, I define a function add that takes two objects and sums them together. And I call add with two different types. First with just integers and second with floats. So, let's look at what this produces. Here is the output of add in Julia. So, first we have add, a function with one method. I'm going to explain this in a second. And then we have our return values 12 and 12.0. What we cannot see here is that Julia has specialized code for the two different function calls. For integers and for floating points. Let's make this more explicit by specifically providing a new method for the case with floating point. So here, now I have an add function specifically for floating point. Instead of taking A + B, this returns A exponent B. Let's call this. And what we can see here is that now we have two methods. So, we add a new method to the same function. This is a method that is specifically for floating points. And instead of having the value 12, we have 100. And this is where the trick lies. Julia compiles the most, um, specialized version that can be compiled. So, a version with integers, a version with floats. And in this, compiling is an actual compilation with LLVM with optimization and so on. This is not just ahead of time compilation. Soon as the Julia knows the type, a function is compiled if it's not compiled already and then it's used. When types are stable and well inferred, this can lead to code that is as performant or comparable to C and Fortran. So, this is what makes Julia, Julia. Multiple dispatch with just ahead of time compilation of highly efficient code. So now, what makes Emacs, Emacs? Well, in my opinion, what makes Emacs, Emacs is interactivity, extensibility, and community. And I claim that Julia has the same three. Interactivity, extensibility, and community are three key pillars for Julia. More specifically, Julia encourages a REPL-driven, introspective, interactive workflow. It's largely open to extension and modification to the point that most of Julia is written in Julia. And Julia has a thriving and welcoming community with lots of packages. So, let me showcase a little bit of this REPL-driven, introspective, interactive workflow with the hope that commonalities with Emacs will emerge naturally. So, let's start by opening a Julia REPL. Here, I have a Julia REPL. Let me give you a tour of the Julia REPL. So, the REPL comes with lots of useful features, from a shell to a package manager. So, for example, let's add the random package. Um, yeah, I have the random package. I can look at what's inside. We have the statistics with random in this particular environment. Environments are fully declarative. So here we have the dependencies of this environment. And I can explore in this manifest, the specific versions that are used. So we have a shell, we have a package manager, and then we have a very powerful help system. So, for example, I can ask for help for length. And here we can see we have, well, the help for length. Lots of information about how to call length, the expected return values, examples. And now you can probably start seeing that this is not that different from calling length. So this is the output for length, or for help for length in in Emacs. So we have help, and we can do more. We can even look at the source code for length. So now, what we can see here is that now, well, we cannot see because it's zoomed in because the font size is huge, but in this page here, we can see the implementation of length. It's this line here in the middle, or these few lines here in the middle. And as you... Let's do this again. As we can see here at the bottom, what we are looking at, this is the source code of Julia. We can change this. There's even a macro edit if you want to change its length. And yeah, I use the word macro. Julia supports metaprogramming. And actually metaprogramming is one of the key features in Julia. It's used extensively in the core, but it's also used extensively in packages, both to extend the Julia ecosystem and functionalities, but also to develop full domain specific languages. Some of the useful macros are, well, I don't know, like time. Here, we have a built-in basic performance tool in in in Julia. And I want to showcase more introspection, macros. But for that, I'm going to do it slightly different. I'm going to open a file example.jl where I define a function, or our function add, there was an asterisk and I will go back to that in a second. So now, I am going to include this this file, and I can call my function add, one and two, and we get three. And now, what I can do is this. I can look at what code gets compiled when I call my when I call 1 + 2. And here, now we can see that there is some integer stuff. But if I make this floating point, now the compiled code changes. Now, maybe assembly code is a little bit too hard to read, so I can look at the LLVM IR representation. In this case we can see that there is promotion. The promotion will probably go away if I make everything float. So this we have F add, floating point add for a double, but we can also look at the Julia lowered representation after the abstract syntax tree is produced. The reason I put this in a file is because now what I can do is I can change this. And now, one and two will be two. So this to me is very reminiscent of how I work in Emacs, where there is a global state that I can access and modify any time with no restrictions. And this happens in in Julia too. Typically, we don't want to modify functions that are in other packages or they are in base, but we can do that. For example, I can change what is plus for integers. And if I change with this plus and make it so that any two integers return zero, well, I can do this. This will break Julia because, well, Julia is built in Julia. So if we break this, well, nothing will work. But I can do that. This to me is one of the signs of the powerful, introspective, and powerful interactive type of workflows that Julia enables. Finally, I want to talk about the general registry. This is the equivalent of Melpa. It comes with with Julia. But this is very akin to Melpa. It's built upon Git essentially. It's collaborative, as relies heavily on GitHub, GitLab. It's heavily automated. And comes with lots and lots of tools and packages. What's beautiful about all these tools and packages is that in the same way many of Emacs packages just play nicely with each other without any input from the developers, the same is true for Julia packages. The Julia packages are highly composable, so two developers can develop two distinct packages that end up playing nicely together for free because of the intrinsic structure, intrinsic way Julia objects are built. So, with all of this, I also want to mention that the community, in addition to have all these packages, is highly active, highly collaborative. The community meets regularly on places like Slack, as opposed to the Emacs community that I'd say maybe meets on Reddit. So, with all of this, I want to thank you for your attention, enjoy Emacs, and enjoy Julia.

Q&A transcript (unedited)

[00:00:00.089] Q: Do you have any suggestions for interactive debugging of Julia code in Emacs?
... answer to that. I, I think the infrastructure for an ecosystem in Julia in general is as mature as other languages, and even debugger infiltrator themselves are not particularly well developed. And so I don't think there's much we can do about that right now. I think that it's unfortunate that most of the development for these type of tools is tightly linked to VS code. But even there, I don't think that there's much done in terms of interactive debugging. So I, yeah, I think this has to be worked on mostly on the Julia side first. And then probably Emacs can get something out of that. I know that there's development in debugger.jl itself for future releases to make it at least faster and more stable. But yeah, I think we're not there as Julia community itself. So let alone Emacs, integration with Emacs. The way I personally debug is mostly using, well, debugger and infiltrator with Julia REPL mode in
[00:01:08.286] Q: Can you call out something that Julia has that Emacs does not, and which could benefit Emacs?
Emacs. The second question, can you call out something that Julia has that Emacs does not and which could benefit Emacs? Nothing stands out to me except the usual multi-threading and things like this. I don't necessarily see something that Julia has going on that DMX doesn't have, but I see some differences and approaches that I think are important, like the community. I think Julia is a very active and tight community. Julia uses Slack and is very, very active. I think he might say something like that, but it's maybe more on Reddit, IRC. JuliaCon is big and brings together lots and lots of people. And I think the sense of community is really powerful. It's very easy to essentially meet people that are interested in what we're building and interested in what we're doing and interested in Julian, our, you know, hacker spirit. I think Emacs is a very strong community. We're here on a Saturday talking about Emacs, which again proves that we are doing this. But I'd like to emphasize that the community is a really important aspect in Julia that I think we should double down on our side. The next question is
[00:02:36.797] Q: Is there a way to use lisp syntax with Julia, like hy for python or lisp flavoured erlang?
about Lisp syntax with Julia, like what we can do in Python. I don't think that's, I don't, I am not aware of any package that does that. I would bet that there's something there. I think that that's possible. Indeed, there used to be a Lisp interpreter in Julia itself until the latest release. The syntax parsing was done with a Lisp, it was called TemtoList indeed. I think this got rid, get rid of this for our more Julia-based solution that is faster and with better code provenance. I think that it should be possible to use the metaprogramming features in Julia to change the structure of your syntax to be a Lispy syntax. I do want to emphasize that Julia is heavily inspired by Lisp, so I wouldn't be surprised if if something like this were possible. I have tried Julia Snail.
[00:03:51.168] Q: Have you tried the Julia Snail package for Emacs? It tries to be like SLY/SLIME for Common Lisp.
So the next question is about Julia Snail. I found Julia REPL to be a little bit easier to set up and use. So I just settled on that. I should maybe revisit that. In particular, I use the Julia REPL with the vterm backend, which essentially makes a companion REPL to my scripts. And that works for me. I do think that the tooling uh, could be improved. I think there is definitely much room and I would like to see improvement in that area. Um, and, uh,
[00:04:22.940] Q: Is there a data inspector for a Julia REPL available that you can use in Emacs?
so we have data inspector for Julia REPL. I don't think so. I don't, is there any data inspector in for, for the Julia REPL that we can use in Emacs? I'm not sure. I don't think so. I think the way I look at data is essentially ignoring Emacs when encoded. It's just using the REPL. And again, with Julia REPL. So I'm not aware of any specialized tool And again, maybe this is, again, a good moment to emphasize that tooling, the Julia community clusters around VS Code. And there is tools like the, pretty much all the work with VS Code, unfortunately. And while there's a very, very decent Julia mode and Julia repo mode and Julia snail, there's definitely, definitely room for improvement.
[00:05:24.443] Q: Have you tried literate programming Julia (using Org babel or some other means) in Emacs?
Next, we have a question about literate programming in Julia. I haven't done much of it with Org Babel or anything else. I haven't done much of it. I can say that Julia has developed a new iteration of notebooks called Pluto. Here I'm thinking about Jupyter notebooks. The Pluto notebooks for Julia try to remove a bunch of the pain points that Jupyter notebooks have, meaning you cannot easily commit them to Git or things like this. I haven't used them, but I know some people are very fond of them. And so I think that that's what some of the Julia community would use for notebooks. And I think they can interact with Emacs with no problem. And that would be a form of later programming. But if you can do it in Python, you can do it in Julia. I think there is no reason. And actually, you can take advantage of all this just-in-time or just-out-of-time compilation by keeping the same session. So I think it will be definitely a nice use case. So these are the questions that I see here. I'm going to scroll through the comments and see if there's something that I should say about comments. I'm excited people want to learn Julia. I have to say that if I want to do GPU computing nowadays, I find it much easier to do it with Julia than with CUDA. So I encourage people to look into that. And I do, again, I would like to share what makes me excited about Emacs, about this being open, being collaborative, being respectable with documentation is something that I find in Julia. So I think people that are excited about the same features will find a little bit of joy in working with Julia. I think I addressed what I have here. I don't know if there's anything else that I should add. It took me a minute to unmute there. No, I think that was awesome. And thank you so much. I guess I thought it would collapse that shared area on BBB, my mistake, on the stream, or I would have left it open. But in any case, no, I thought that was great. You did a great job of responding to all the questions and comments. And thank you again so much for your talk and getting us all excited to learn Julia. Thank you. Enjoy EmacsConf. And again, thanks so much for attending, for being EmacsConf. Thank you.

Questions or comments? Please e-mail emacsconf-org-private@gnu.org

Back to the talks Previous by track: p-search: a local search engine in Emacs Next by track: Beguiling Emacs: Guile-Emacs relaunched! Track: Development