Comp 110 Interactive (REPL) vs Stored Programs

Interactive Programming vs. Stored Programs

What is 'Interactive Programming'?

Interactive programming is a type of programming where you can enter a command or expression and immediately get back the result. One way to program interactively is through the console on Google Chrome. To open it on Windows, the shortcut is Control+Shift+J, and to open this on Mac the shortcut is Command+Option+J.

With interactive programming, we are working in a REPL. This stands for Read, Evaluate, Print, Loop. In this process, the computer takes your command (read), processes it (evaluate), gives you back the result (print), then lets you enter another command (loop).

Interactive programming is nice if you're testing things out or just want to try some new things. The catch with interactive programming is that once you refresh the page, your previous commands will be lost! If you're writing code you think you might want to come back to at some point, writing stored programs might be a better choice than interactive programming.

So how do I open a REPL?

  • Navigate to bit.ly/repl-110 in Google Chrome
  • Open the REPL:
    • Windows: Control + Shift + J
    • Mac: Command + Option + J
  • Start programming!

Some interesting examples to try out;

  • Anything that evaluates to be an expression!
1 + 2 ** 3 % 3 + "4"
let x = 100
let y = 40 
(x<110) &;& || (y>101)
let myName = "kris"
"My name is " + myName
let a = "1";
let b = "2";
let c = "3";
let d = b + c + b;
let e = a + d + a;

What are 'Stored Programs'?

When you write a stored program, you're writing your code in a file. Stored programs, unlike interactive programs, won't give you immediate results with each line of code you enter. The computer only evaluates your code once you save and execute the file. Once you do this, you'll get the results of all the code you entered, even though the computer still runs through each line individually. 

When you are in the process of writing a stored program, you're telling the computer each step of what you want it to do, but the computer is still not executing any of the commands you are entering. After you save your program and run it, the computer actually follows the directions you wrote and does what you specified. Each time you restart the program, the computer starts from the beginning and evaluates everything in the file all over again.

The good thing about stored programs is that you can save the file so you won't lose your code and can come back to it. All problem sets will be done as saved programs.