crispinb

crispinb

The background to this is that I’ve (a) recently been doing some Clojure and am slightly addicted to the REPL-connected editor, and (b) I’m a total Elixir beginner (1 week in), so all my coding is at this stage “exploratory” (playing with examples from what I’m reading, trying out Kernel functions, etc).

Here’s what I’ve come up with so far:

  • iex: fine for one-liners, but a bit clumsy for anything more, and I’d much rather use an editor (and preferably the same editor I would use for real code)
  • iex -S mix, then calling on functions in files, reloading after edits: better, but still more friction than I’d like
  • via unit tests, writing small tests for the exploratory code & running mix test. A variation here is to use fswatch to run tests on every file save, but I haven’t got this working yet.
  • again via unit tests, but triggering tests from the editor (in my case using GitHub - adamzapasnik/vscode-elixir-test-explorer: VSCode Elixir test explorer · GitHub).

The final one above seems the most fluent approach so far, definitely workable, though ideally I’d like not to have to write tests for this kind of very transient exploratory code.

Any other ideas? I realise I’m not going to get a lisp-style repl experience (which is fine - Elixir has its own virtues), but something in that direction would be nice. A non-clojure example I quite like is Quokka for javascript/typescript.

Showing Posts 1 to 9

hauleth

hauleth

Well, you can start the “REPL-like” server that will receive the code, and then will use Code.eval_string/3 to execute whatever you throw at it. It will provide similar experience to the SLIME.

About unit testing, what I am using is entr. So you need to list all files in your project (I am using rg -l -telixir '', but you can use git ls-files instead) and then make it to output name of the changed file entr echo /_ that will pass the changed files to mix test --listen-on-stdin --stale. So whole CLI will look like:

rg -l -telixir '' | entr echo /_ | mix test --listen-on-stdin --stale

Now it will changed tests on each save.

Marcus

Marcus

Maybe you will find exsync and mix-test.watch useful.

crispinb

crispinb OP

Thanks for the options, @hauleth & @Marcus. For now I think unit tests with a watch are going to be the best approach. I don’t want to spend much time on tooling for now - learning Elixir & Phoenix will be enough cognitive load :wink:

Would like to look into the option of sending selected code from the editor to be eval’d at a later stage though.

dhruvp

dhruvp

I just finished going though a Common Lisp book (Gentle Introduction to Symbolic Programming) and really like the repl driven development. I also learned some Emacs along the way and that’s the editor I am using to learn Elixir. Currently going through the book Programming Elixir >= 1.6

Looking for a similar learning/development approach in elixir, where I code in the editor and verify the code is correct by evaluating the text in the editor, the text is evaluated against an elixir repl. This is very handy because there are times where I just want to check if the code is correct without leaving the editor.

Here are the tools/packages I am using:

Editor: Emacs
Emacs Packages for elixir:

  1. inf-elixir: GitHub - J3RN/inf-elixir: An Emacs plugin for interacting with an Elixir REPL · GitHub
  2. lsp-mode: Elixir - LSP Mode - LSP support for Emacs
  3. elixir-mode: GitHub - elixir-editors/emacs-elixir: Emacs major mode for Elixir · GitHub

If you need a detailed setup, let me know, I can push it to a github repo.

crispinb

crispinb OP

Nice. Just what I would want if I used emacs. It’s one of the missing parts of the elixir ecosystem more widely.

mindok

mindok

If I was starting out and wanting to play around with code, LiveBook (https://livebook.dev/) would probably be my #1 choice now. Instant feedback, nice formatting etc.

crispinb

crispinb OP

Agreed, it’s terrific. Not exactly the same as using your own REPL-linked editor (different keybindings etc), but with lots of other great possibilities.

mattbaker

mattbaker

This might be what you meant by “reload” but just in case: if you haven’t found it r/1 In IEx will let you recompile a module on the fly, i.e. r(MyProject.MyModule). Beats terminating and restarting IEx!

At one point I had a hacked together VS Code extension that let you recompile the current file you were editing in an attached IEx session but I never followed through to ship it.

crispinb

crispinb OP

I do know about r/1 now but the question was a while back and I have no idea whether I did or not back then (or whether that was what I meant by ‘reload’). So thanks from my erstwhile self!

Ironically (or sadly from this perspective) I’m doing more with Rust right now than Elixir, so I’m even further distant from REPLy goodness.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews