5 ms·
The REPL is still something that I haven't quite mastered, but what I enjoy doing right now is working in files and using a REPL connection to evaluate expressi
by piercebot 6y ago
The REPL is still something that I haven't quite mastered, but what I enjoy doing right now is working in files and using a REPL connection to evaluate expressions within the file. It feels like a happy medium between "do everything at an (ephemeral) REPL prompt" and "do everything in a file, save, and reevaluate the file."
My weapon of choice right now is vim-iced[0], which is a batteries-included VIM plugin that, in addition to providing a REPL and keybindings to evaluate expressions under the cursor, also allows me to auto-format my files on save.
[0]: https://github.com/liquidz/vim-iced https://github.com/liquidz/vim-iced
- reddit_clone 6y agoYep. Thats what I do too. For emacs users, 'eval-region' and 'eval-expression' are your friends.
- jetti 6y agoIf you are doing Clojure development in emacs CIDER makes things super easy. Loading files or buffers into a repl as well as eval region and sexp (there are a ton more features but those are the main ones I use) Edit: I should have included a link for CIDER: https://cider.mx/ https://cider.mx/
- Jtsummers 6y agoAnd if you have language support in org, use an org file. #+BEGIN_SRC lisp (+ 1 2) #+END_SRC #+RESULTS: : 3 (type C-c C-c inside the source block) If you use noweb it'll also include referenced blocks in the evaluated unit: #+NAME: foo #+BEGIN_SRC lisp (defun foo (n) (+ 1 n)) #+END_SRC #+BEGIN_SRC lisp :noweb yes <<foo>> (foo 2) #+END_SRC #+RESULTS: : 3 This lets you have many versions of code in one file (if that's a sensible thing for you, very useful when exploring a new library or concept though), and in the end you can aggregate it all into one source file for sharing with others: #+BEGIN_SRC lisp :tangle foo.lisp <<foo>> <<bar>> #+END_SRC (type C-c C-v C-t to create the file) I've mainly used this (for interactive development) with Common Lisp, but it should work for most other languages that offer similar interactivity.
- dgb23 6y ago> The REPL is still something that I haven't quite mastered, but what I enjoy doing right now is working in files and using a REPL connection to evaluate expressions within the file. For me that is the optimal way of doing things. I want to restructure stuff, make multiple versions of functions, move them in and out of comment blocks or just leave code there for REPL use. When I first saw someone writing Clojure like this on a video I was thinking: "This is the way I want to write code." I think this is the best of both worlds.
- adamkl 6y ago> I want to restructure stuff, make multiple versions of functions, move them in and out of comment blocks or just leave code there for REPL use. I think programming at the REPL requires a very different mindset from how a lot of us learned initially. The thought of leaving commented code in our codebase is one of those things we're told not to do, but there's a great snippet from one of Stuart Halloway's talks where he mentions "Rich Comments" (pun intended I think). Rich is apparently known for leaving REPL code inside comment blocks specifically for testing purposes, and as a sort of transcript of the work that was done. [0] Its a great approach, and one that I've adopted, but it seems wrong at first glance when taken out of the context of a REPL. [0] https://github.com/clojure/clojure/blame/4ef4b1ed7a2e8bb0aaaacfb0942729252c2c3091/src/clj/clojure/set.clj#L158 https://github.com/clojure/clojure/blame/4ef4b1ed7a2e8bb0aaa...
- xapata 6y agoI like the practice of leaving REPL examples in docstrings, especially if I can include Python's `doctest` in the test suite.
- deleuze 6y agoWow, this just blew my mind. I usually keep a bunch of ; commented out lines at the bottom of my file so I can still do M-x cider-eval-buffer when I load up for the first time, but this makes so much more sense without having to comment and comment things all the time.
- lgessler 6y agoYeah, something I've seen become common in the Clojure ecosystem is for files to have a `(comment ...)` form at the bottom where forms which are commonly needed at the REPL when working with the file (e.g. to initialize some data or a database connection) are kept around. Editors like IntelliJ with Cursive have commands like "evaluate sexp before cursor" which lets you easy use them, and since they're all commented out they don't effect the normal execution of the code.