Editor Integrated REPL Driven Development for all languages

Musa Al-hassy (he/him) - Pronunciation: moo seh, http://alhassy.com/ https://github.com/alhassy, Alhassy@gmail.com

Format: 10-min talk; Q&A: ask questions via Etherpad/IRC; we'll e-mail the speaker and post answers on this wiki page after the conference
Status: All done

00:04.880 Introduction 00:35.989 The wonders of C-x C-e 03:35.809 An overview of REPL Driven Development 04:51.143 REPL Driven Development with Java 07:28.029 Bring your own Read Protocol 07:59.669 Use Case: RDD & Job Interviews

Duration: 09:37 minutes


Emacs’ C-x C-e is arguably one of its killer features: The ability to run arbitrary Lisp code, anywhere. We demonstrate that the idea is portable to other languages [0, 1]. The result is an Emacs interface for any language, where code of your choosing is evaluated, and results are echoed at your cursor in overlays. We will demonstrate how to solve simple problems such as FizzBuzz in a RDD style using, say, Java or any language that the audience chooses. We will also look quickly at "growing programs" such as a photo gallery application, starting from scratch. Along the way, we discuss what features make a RDD system pleasant and how they can be implemented with our system. Finally, we conclude with how this RDD setup allows for inserting results of a computation as a use case for writing tests —i.e., we we show how user-definitions of a read protocol (the 'R' of 'REPL') can result in an analog of C-u C-x C-e.

[0] 💐 Repl Driven Development: Editor Integrated REPLs for all languages 🔁


[1] REPL Driven Development :: Teaching a JavaScript runtime, incrementally, to be a web server 🍽️ 🔁 �


About the speaker:

Musa is an Emacs afficando. His day job is with Java, but his heart is with Lisp. His experience with interactive programming is only with Agda [2] and Emacs Lisp [3], and both [4].

[2] Graphs are to categories as lists are to monoids


[3] A Life Configuring Emacs


[4] Making Modules with Meta-Programmed Meta-Primitives http://alhassy.com/next-700-module-systems/prototype/package-former.html


Questions and answers

  • Q: I know that there are many packages for creating graphics with Javascript, but I don't know how to use any of them... is it possible to use your package to create graphics in Javascript step by step from Emacs?
    • A:
  • Q: Can you summarize what languages your packages support and do you have a common framework for interfacing to their interpreters?
    • A:
  • Q: Did you get the job?  =)  Did the interviewer have any feedback about your screen-sharing-driven development?
    • A:
  • Q: Could you compare your package to Language Servers (LSP)? They seem to have similar functionality to your package.
    • A:


[00:00:04.880] Introduction

Hello, and welcome to EmacsConf 2023! My name is Musa Al-hassy, and I will be talking about "REPL-driven development." I like programming languages so much. I want to use them all over the place. I got a PhD in the topic. So let's just dive in. This is a lightning talk, so the details will be available in the repository. Links to longer videos and GIFs for those who are interested.

[00:00:35.989] The wonders of C-x C-e

So the wonderful thing about Emacs is that you can execute Lisp anywhere. For example, I can go to this piece of Lisp, press Ctrl-x Ctrl-e (C-x C-e) and get a little pop-up. Alright, so here I pressed C-x C-e and this is what it ran. And what this package gives you is the same ability for any language of your choosing. So for example, here is some Java, and I bound it to Ctrl-x, Ctrl-j (C-x C-j). So I say C-x C-j, and this runs some code, and over here I get a little pop-up. The wonderful thing about being able to run code from anywhere is that you can keep it in normal text files or any kind of file you like. For example, you can have hyperlinks, as it were…, like this one. C-x C-e, and now we can see this down here. Learn about it. But being able to run other languages besides Emacs lets us do some interesting things. For example, in the middle of a JavaScript program, you might write a line like this. C-x C-n. And that says down here javascript-eval in the mode line, and so this just checks that some endpoint is working as intended. So you don't need to use an external tool to check endpoints. You can just use Emacs in your favorite language. You know, you can keep your spirit up. So, C-x C-a runs applescript-eval. The cool thing is, your code immediately takes form. Right away, you see it doing things, you know, altering your environment. For example, this is JavaScript, and JavaScript here is gonna change Emacs for us. So C-x C-n. And you can see down here javascript-eval was invoked. It returned true, and this line of JavaScript altered our Emacs. So that's really nice. So you don't need to use just Emacs Lisp if you like. You can use other systems. As you saw, the output is shown in overlays. So here's, for example, C-x C-p to run some Python code. Notice it blinked in red because I thought red was nice. You can configure as you like. And if you hover over it, you can see the solution there, and you can see it in a variety of familiar ways if you use C-x C-e regularly. You can insert the results. You can find documentation about them. The idea here is that you have this familiar Lisp workflow with C-x C-e, and this package ports it over to your favorite language out. So you can eval things, you can insert them, and do as you like. I think that's really neat.

[00:03:35.809] An overview of REPL Driven Development

This package allows you to do REPL driven development. In that, you can use it to grow your program. You don't need to restart it. You can see changes live. So here's, for example, this is in a Java runtime. You can see some balls bouncing around. I don't really know which one is the second one, but let's increase its size. C-x C-j. And this one increased in size, and you can see down here I pressed C-x C-j. Let's change the color to blue, C-x C-j, the color is blue. So all these changes are happening live. Three balls isn't really a ball pit. Let's go to 50 balls. There you go. So it's nice that you can do this without leaving your environment, without building, you can rapidly modify and see. I think that's nice. Unfortunately, I'm at the halfway point, so I won't be able to work through some of these nice problems, but you can see the videos or GIFs on the associated repo. Likewise for this one. This one would have been a lot of fun, but unfortunately, we're running short on time. Apologies.

[00:04:51.143] REPL Driven Development with Java

The neat thing here is: this package tries to bring the feeling of Lisp to other languages. So the idea of a REPL, or a Read Eval Print Loop is R and P are data interchange protocols. Unfortunately, not every language has those, but this package kind of encourages us to implement them if we don't have them. Let me show you an example. What do I mean here? This is a Java file. I've loaded this definition in. We can press C-x C-j, and you see it's a list of person. I didn't give this a name, so its name is $59. If I hover over it, we can see the definition again. So it's a person called Hamid, age 5, another person called Jaafar, age 6. This pretty printing is nice for me as a human, but I can't execute this. This isn't valid Java. So I could do C-u C-x C-j. If I have the help of a read protocol inserted. Sorry, C-x C-j. There it is. So look, it gives me a new Person with the construction everything. Now I can work with. Java can work with this. So this can be quite useful for regression testing or just to find out what your method spits out. We can do the same thing. Here's a bigger example. Trying to see it in the overlay is a bit cramped. We can say C-u C-x C-j. All right, and now we have executable code. Okay, this is neat. If you want to do something with it. I'm not really interested. I have four new persons. If I really want to look at this, I can say M-x java-eval-navigate-output, and now I see my output as this hierarchical tree. I go down, I can see what's inside these, what's the type of this thing, what's in there. All right, so that's nice. The idea is that we're not limited to just textual output. We can render output, thanks to the power of Emacs, in any way we want. In a browser, in a LaTeX file, in an Org mode (file), however we really desire.

[00:07:28.029] Bring your own Read Protocol

And if our language doesn't have an easy protocol, so what I did for Java in particular was: you take a blob, and you use some parsing expression grammars, or if you really want regular expression pattern matching, and you get some property list out, and then you construct an executable expression out of that. Like this new Person. It's nice that you can do these kind of things and that this software encourages you to do them.

[00:07:59.669] Use Case: RDD & Job Interviews

So one use case I actually use besides learning things is… oops oops oopsies oopsies showing you metadata you shouldn't be looking at. Don't look at my metadata. Sorry about that. One place I actually use this besides learning and trying new libraries and APIs and stuff like that is, for example, when I interviewed for jobs last year (I was changing jobs), I would share my screen, and if the interviewer gave me some inputs and outputs to play with, I could do essentially some sort of test driven development and constantly evaluate things right in front of the interviewer. For some design questions rather than sketching out my ideas in a Google Doc, I would share my screen and be like, "Hey, here's actual executable code, we can stub some things out and have some types," and the idea is we can still check things and run them right there and then, which I thought was quite nice, and it helps to clarify your thought process, I guess. Anyhow, so that's my time, I hope you've enjoyed this little package, and again, sorry for the rush, it's a lightning talk. Feel free to find everything on the associated repo. And have a wonderful December Saturday. Take care! Bye bye, everyone.

Captioner: bhavin192

Questions or comments? Please e-mail Alhassy@gmail.com