Interactive Programming

Published Sun Feb 04 2024

I advocate for many tools that validate or test the quality of your program before it is ran. This defensive style of programming is effective, but has some limits. Interactive programming is an interesting alternative style; instead of verifying before execution you can look into a running program and change values while it is running. Using Fennel with Conjure I have begun to get a taste of interactive programming. Rather than adding logs or debuggers interactive tools enable me to run a specific block or line of code to quickly iterate.


In my floating journal post I wrote a function to open a floating window with today’s Neorg journal. While working on this I could have made edits, reloaded my config, and viewed the result of my updated keymap. In this case the workflow is not incredibly tedious, but with interactive programming I can run parts of my code to see what it is doing. For example opening a floating window:

(let [
  ed_width (vim.fn.winwidth :%)
  ed_height (vim.fn.winwidth :%)
  win_width (math.floor (* ed_width 0.6))
  win_height (math.floor (* ed_height 0.8))
  bufnr (vim.api.nvim_create_buf true false)
  (vim.api.nvim_open_win bufnr true {
   :width win_width
   :height win_height
   :row (/ (- ed_height win_height) 2)
   :col (/ (- ed_width win_width) 2)
   :relative "editor"
   :border "rounded"
   :title "Daily Journal"
   :title_pos "center"

With this code block I can use Conjure’s <leader>ee to evaluate this form, executing the code and printing the result or in this case opening a floating window. Interactive workflows are part of the appeal of lisp languages, but Conjure works with some non-lisp languages too! This can also be done with Lua, if you have no interest in lisp I encourage you to still try this out. You can get going with Lua or even Rust. Download the plugin and :ConjureSchool it up!