I've just finished reading the guide. It is very nicely written and
provides a great start, but it raises a couple of questions I have not
been able to find answers to.
1. What's the difference between throw and raise? As far as I can
tell, they're orthogonal, meaning that I can only catch a thrown value
and rescue a raised error. What's the intention of having these two
separate things that are somewhat similar?
2. Why do we need to use a dot after a variable name when the variable
is a function? A related question is how can I get the value of a
built-in function?
This makes sense and I think it's a good choice to reserve exceptions
for truly exceptional cases. In Objective-C land, for instance, exceptions are
likewise only used for programmer's errors.
The point to make here is that at some point in the future we'll need
an example in a working app or a short write-up on this convention
established by Elixir, since it's not mentioned at all in the guide.
Every language I know of uses prefix notation for an operator when its
meaning is "dereferencing" or "extraction of value".
This is one way to interpret the situation. One other way we could interpret it is considering that functions are anonymous and therefore don't expect a name to be given on invocation. For example, imagine we have a module named List. If we want to invoke a function of that module, we need to pass a name, for example, flatten:List.flatten([1,2,3])However, functions doesn't require a name to be invoked, and therefore we can omit the `flatten`:function.([1,2,3])So we could fit everything under named and anonymous invocation. The expression flatten([1,2,3]) would be a named invocation as well, because it is simply a shortcut to __LOCAL__.flatten([1,2,3]).
Basically you always need a dot to invoke something. But sometimes there isn't anything between the dot and the parenthesis, because the function is anonymous.
Basically you always need a dot to invoke something. But sometimes there isn't anything between the dot and the parenthesis, because the function is anonymous.
I see. If LEFT.RIGHT means "Look for something named RIGHT in the thing denoted by LEFT" then "x.()" means "look for nothing (or something anonymous) in x and try to use it as a function".
I find this approach unintuitive, because I can't use "x." to simply look for that anonymous thing or do a call without parens: "x. 5 # this doesn't work".
I think we've both demonstrated our points of view and this discussion will lead nowhere unless more people join and share their feedback. At least we'll be able to point newcomers to this discussion in case someone has similar problems with the dot as I do :)