Local accumulators for cleaner comprehensions

I like the idea of the accum block; in fact, I had thought about it myself, as did a few others in this thread. It just feels like a natural fit for Elixir. To me, it serves as a signal for the scope, somewhat discouraging its usage (which is good) due to the longer syntax and indicating that it’s something special.

I also believe that a visual marker is necessary to differentiate it from “normal” variables. Perhaps something like @@my_var, !my_var, &my_var, &&my_var, etc. The last ones might give off a “mutable” vibe for those familiar with C/C++/Rust.

I don’t think there needs to be a separate operator for this, considering how it would work with pattern matching.

So, for me, something like this looks good:

accum &my_var: 123 do
  ...
end
3 Likes