I’ve been curious why some things, like with
, are special forms when they can fairly easily be done via macro’s? Take the happy
library, that gives you a happy_path
macro, which is basically with
(implemented internally via nested cases). Wouldn’t making with
a macro have been easier? Or why was it made a special form in the first place? The variable arguments is not really necessary as everything can be done within and inside of a block like happy
did?
As an example from online take this Elixir standard with
:
with {:ok, binary} <- File.read(path),
{:ok, data} <- :beam_lib.chunks(binary, :abstract_code),
do: {:ok, wrap(data)}
Or perhaps compare to this:
with do
{:ok, binary} <- File.read(path)
{:ok, data} <- :beam_lib.chunks(binary, :abstract_code)
{:ok, wrap(data)}
end
First of all the elixir way as it is currently is really really hated by auto-indentors in emacs/vi/atom. Second the first method does not fit with the style of case and other things. Third the second method has a block and reads like normal code but with weird <-
for matching, but no weird comma’s needed, the last expression is what is returned, like everywhere else in Elixir. Fourth, you can even pass in options easily, like perhaps an extension that allows you to pass in an unhandled error handler or so:
with unhandled_errors: &handle_unhandled_errors(conn, &1), do
{:ok, binary} <- File.read(path)
{:ok, data} <- :beam_lib.chunks(binary, :abstract_code)
{:ok, wrap(data)}
end
Which is also consistent with other things in Elixir.
There are other reasons too but I’m getting about a frame every 4 seconds while typing this in either Chrome or Edge (I really really hate Windows) so I’ve no clue what I’ve even typed yet as it has not shown up yet. ^.^