REPL I/O in a Pkg instead of `readline()`?

Hi everyone,

Working on a package to give interactive tutorials for new Julia users. Hit a stumbling block that I’m not convinced has a good answer. Basically here’s what I want to happen:

Hi juliatutor user type `println("hello world")` and hit the return key.
> println("hello wurld")
hello wurld
Sorry that's not the solution we asked for try again.
> println("hello world")
hello world
Good job! Let's move on to the next task.

So far I was able to mimic this behaviour with the readline() function. But there are serious downsides to using that function when compared to a typical REPL input! For example, hitting the arrow keys in a readline displays some character annotation for the keypress and doesn’t move the cursor (eek)

julia> readline()
^[[D^[[D^[[D^[[C^[[C^[[C

This would frustrate a new user and not provide anything like the REPL experience they would get by closing the package. Full REPL incorporation isn’t needed, but being able to get something closer than readline() offers would be awesome.

The current code for this can be found here:
https://github.com/caseykneale/JuliaTutor.jl/blob/dd1a8bb618a3c91bc8b8e525f16990eddc7fd54a/src/Prompts.jl#L36

I’ve looked into REPLMaker.jl at the suggestion of others and the base code for REPL’s itself but quick attempts at getting what I wanted didn’t work out. Does anyone have any good ideas for this? Or is this hopeless for now?

That’s pretty much what you are going to have to use though. For inspiration, you can look at Pkg, Debugger for custom REPL modes.

2 Likes

I for some reason didn’t think to look at Pkg, or Debugger. Great idea. I’ll take a peek at those sometime soon and give this another try. I know how I’d go about doing this in another Language but in Julia it’s a little more nuanced so following the road more traveled should help a lot.

This is one of the goals of Pluto notebooks. Have you seen the homeworks for our course, for example?

https://computationalthinking.mit.edu/Fall20/hw1/

2 Likes

I didn’t know that! No I haven’t seen your homeworks, but I did star the repo. Figured I’d jump in once you all get past the image stuff I already know :).

Have you ever heard of Swirl, it’s an R package? CRAN - Package swirl

Swirl taught someone who I thought would take months to write code to do so in a matter of a week or so. Albeit dangerously. So I wanted to make something like that in Julia.

The code I have for evaluating answers came from @travigd who was also working on automated course work evaluation code as well.

If you (MIT/JuliaComputing people) all are already working on this I can just trashcan the project. Nothing like this existed when I started it otherwise I wouldn’t have bothered.

Will you by any chance be open-sourcing how you make the notebooks?

I haven’t heard of Swirl.
It certainly doesn’t hurt to have multiple projects.
Probably some people prefer using the REPL.

Everything is contained in the notebooks themselves (or in Pluto).

1 Like