Taking greater advantage of let blocks

I’d like to make greater use of let blocks for testing out code, especially code where I’m defining types so that I can make definitions and play with them to see if what I’m doing works without polluting my namespace and possibly needing to restart my Julia instance.

One thing that’d be really amazing for this would be allowing one to incrementally evaluate code inside a let block. Right now at the REPL if I enter

let
    const x = 1
    x + 1

nothing happens until I supply an end. It’d be pretty neat if instead, the REPL evaluates each line inside the let environment incrementally and displays the output. This could allow one to use a let block kind of like a REPL mode where you and try things out and then exit without polluting your namespace or requiring restarts. Is such a thing feasible or is it forbidden by the way Julia handles let blocks?

1 Like

If you are using any reasonable IDE (Emacs/VSCode/Atom) you should be able to just edit your code as

let
    const x = 1
    x + 1
end

and send it to the REPL, thus avoiding the creation of temporary variables.