DEV Community

Vee Satayamas
Vee Satayamas

Posted on

[Programming Notes] Pseudo-REPL-driven programming in Rust with Evcxr and Emacs

I want to develop my Rust library more interactively with Lisp-style read-eval-print loop (REPL). So I wrote this post to show how I used Excvr - yet another REPL for Rust, and inf-excvr - yet another Excvr wrapper for Emacs, step-by-step.

  • I cloned the project the wordcut-engine project, and open README.md in Emacs.

Image description

  • I ran inf-evcxr, which it created a new inf-evcxr window.

Image description

  • I add the project as dependency by running inf-evcxr-add-dep-current-project.

  • I marked a region over use commands, and ran inf-evcxr-eval-region.

Image description

  • I marked a region over initialization code block, and ran inf-evcxr-eval-region.

  • I moved the cursor to let txt = "หมากินไก่"; and I ran inf-evcxr-eval-line.

  • I moved the cursor to wordcut.put_delimiters(txt, "|"). Then I ran inf-evcxr-eval-line. The REPL printed the result of word tokenizer (wordcut::put_delimiters).

Image description

  • I did the same on wordcut.build_path(txt, &txt.chars().collect::>()). The REPL printed a graph that used for word tokenization.

Image description

  • I could let the REPL show prettier result by evaluating dbg!(wordcut.build_path(txt, &txt.chars().collect::>()));.

Image description

  • I redefined txt to กากินกิน, and ran the word tokenizer again.

Image description

This allows me to experiment with and manually test functions by varying the input variables to different strings and checking the results in simple strings or even internal structures, without recompiling the program or reloading the data. This is helpful for manual testing and debugging.

Top comments (0)