Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I add my own nitpick about the with statement.

If I start with this code

  true = is_email_address?(email)
  true = EmailAddresses.is_available(email)
and I decide to turn it into a with like this

  with true <- is_email_address?(email),
       true <- EmailAddresses.is_available(email) do
then I have to go line by line replacing = with <- and adding a comma at end of line. Sometimes there is a long list of lines to wrap. Surely it can be automated by an IDE or a macro of the editor. Anyway it's still a bad choice IMHO.

I understand why with could not work with the = matching operator (it's a macro) but that's about language design, ergonomics and in part not making developers do the job of the compiler.



Your two examples aren’t quite equivalent.

  true = false
raises a match error while

  true <- false
in a with statement doesn’t.

You can actually use true = false in your with statement, but it will still raise the match error.


> I understand why with could not work with the = matching operator (it's a macro)

Not sure what you mean - `with` _can_ use the `=` operator, e.g. you could write:

      with true = is_email_address?(email),
         true = EmailAddresses.is_available(email) do
        # something
      end
Although this is rather pointless as it's functionally equivalent to just writing:

     true = is_email_address?(email)
     true = EmailAddresses.is_available(email)
     # something
`=` is useful inside `with` if you have a clause that _must_ return a particular value or it's an error, i.e. you don't need to match on any other possible return value. But if you don't have at least one clause with `<-` then `with` achieves nothing.

Also, why would the fact that `with` is a macro mean that it can't use `=`?




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

Search: