Hacker News new | past | comments | ask | show | jobs | submit login

`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



Actually 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...

> 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.


> 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: