News for hackers. Stuff that matters.
Re:Thoughts on Elixir, Phoenix and LiveView after 18 months ... by sph on Monday August 14, 2023 @04:31AM (#37118737)
Guards are very small, very fast functions built in the BEAM VM.

is_integer is a guard (in pseudocode: cell.type == TYPE_INTEGER).

URI.char_reserved? is too high level to be builtin the VM.

Same for the hypothetical is_keyword_list mentioned above. How would you know if something is a keyword list?

1. It is a list

2. The first element is a tuple of 2 elements

3. The first element of the first tuple is a keyword

4. Every other element in the list obeys #2 and #3

What if you pass a list with a million elements to a guard like that? The VM would grind to a halt traversing every single element to make sure the whole thing is a Keyword. This is why there is no such guard.

So sure, you might have to consult the docs for what's a guard and what is not, but can also be understood intuitively.

Re:Thoughts on Elixir, Phoenix and LiveView after 18 months ... by Munksgaard on Monday August 14, 2023 @04:42AM (#37118802)
Your point is rendered moot by the fact that `in` is allowed in guards. See my other response as well.
Re:Thoughts on Elixir, Phoenix and LiveView after 18 months ... by sph on Monday August 14, 2023 @05:37AM (#37119110)
That's a fair observation. Perhaps the exception that proves the rule.