donkirkby / live-py-plugin

Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
https://donkirkby.github.io/live-py-plugin
MIT License
291 stars 57 forks source link

Add REPL mode to browser. #267

Open donkirkby opened 4 years ago

donkirkby commented 4 years ago

While reviewing tutorials for #262, I found a lot of them use the REPL at the start. A typical example:

>>> 2 + 2
4
>>> 50 - 5*6
20
>>> (50 - 5*6) / 4
5.0
>>> 8 / 5  # division always returns a floating point number
1.6

Some of them use multiline expressions:

>>> for i in range(5):
...     print(i)
...
0
1
2
3
4

I think new learners find those are easier to approach than full scripts, but they don't fit with the live coding approach. A hybrid approach would be to add a REPL mode that lets the user type new lines at the end of each code sample. Ideally, the up arrow would even let them cycle through the lines in the sample.

The code module has tools to emulate a REPL, including help deciding when an expression is complete and when you should ask for another line.

It might be possible to fit this into the live tutorial model using cloze tests. The goal could be a REPL session with blanks, and the student has to follow the pattern and fill in the blanks. For example, a goal might look like this:

>>> a = 2
>>> b = 3
>>> a ? b
6

The student would need to replace the ? with *. I guess a rewind button would be needed to fix mistakes.

To define a REPL section, end the code with >>>. The goal can contain lines that start with ^^^ to mark clozes.

>>> a = 2
>>> b = 3
>>>

### Goal ###
>>> a = 2
>>> b = 3
>>> a * b
^^^   ^
6