While - Elixir macro for ruby traditional while - looking for feedback

In my case I’m only using the global version of this while loop, and I use them in tests to start processes and wait for them to come up:

01 test "doing some stuff with workers" do
02   while workers_online() < target do
03      start_new_worker()
04   end
05   ...
06 end

I just prefer being able to write this in-line in the function that needs it than externalizing this every time into a recursive function, especially when it’s not reused:

01 test "doing some stuff with workers" do
02    ensure_workers(target)
03    ....
04 end
05 
06 def ensure_workers(target) do
07   if worker_online() < target do
08     start_new_worker()
09     ensure_workers(target)
10   end
11 end

That’s my reason to create it: Laziness of creating a recursive function for each while use case.

Totally agreed, the hidden rebinding is alarming. That’s why I added the _with postfix instead of just overloading the while macro with two parameters for this. Maybe a name like while_bind would indicate that binding easier. First I looked at i = while_with i, i < 10 do: i + 1 but felt it’s just one i too much…

Just for completeness the two, or more variable version would look like this:

i = 0
j = 0
while_with {i, j}, i < 10 do
  {i + 1, j + 1}
end