4 ms·
`with` is an oddball. It's a macro but it's also a special form that has unique syntax that's not used anywhere else. It's basically the only variadic function
by okbake 8y ago
`with` is an oddball. It's a macro but it's also a special form that has unique syntax that's not used anywhere else. It's basically the only variadic function in the language and it doesn't fit IMO.
It could have been implemented without needing the same special treatment with something like:
with do
x <- foo()
y <- bar(x)
z <- baz(y)
blah(z)
else
err -> handle_err(err)
end
- pmontra 8y agoActually I'd like this with x = foo() y = bar(x) z = baz(y) blah(z) else err -> handle_err(err) end No do (uselessly verbose, it litters all the language) and = instead of <- It should be normal code and take the else branch whenever there is any error, pattern matching included. The advantage is that the code can be indented in or out a with block, without any change. Much more convenient. Elixir also have a try/catch https://elixir-lang.org/getting-started/try-catch-and-rescue.html https://elixir-lang.org/getting-started/try-catch-and-rescue... > In Elixir, we avoid using try/rescue because we don’t use errors for control flow. We take errors literally: they are reserved for unexpected and/or exceptional situations.
- PopeDotNinja 8y ago> No do (uselessly verbose, it litters all the language) and = instead of <- It should be normal code and take the else branch whenever there is any error, pattern matching included. Using '=' insead of '<-' would break how with works. I can understand why one thinks the syntax looks weird. I avoid with when possible, but sometimes it's the easiest abstraction to use.