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.
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`.
[Computer]: You can do it, buddy.
[Musa]: Maybe you heard that in the background?
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.
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.
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.
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.
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.