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, andinf-excvr - yet another Excvr wrapper for Emacs, step-by-step.
- I cloned the project thewordcut-engine project, and open README.md in Emacs.
- I ran inf-evcxr, which it created a newinf-evcxr window.
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.
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).
- I did the same on wordcut.build_path(txt, &txt.chars().collect::>()). The REPL printed a graph that used for word tokenization.
- I could let the REPL show prettier result by evaluating dbg!(wordcut.build_path(txt, &txt.chars().collect::>()));.
- I redefined txt to กากินกิน, and ran the word tokenizer again.
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)
For further actions, you may consider blocking this person and/orreporting abuse