Pronouncing `<-`

When speaking Elixir, how do you pronounce <-, as in a list comprehension, like for n <- [1, 2, 3], do: n * n? Obviously there’s “left-arrow” or “back-arrow” (or worse yet, “less than dash”), to be literal, but I prefer to be more intention-revealing and concise. So, I’ve been using “from”, as I’ve long used for the < common in Unix command lines. Is there any common (maybe even recommended) style?

I can think of a few other possibilities, like “in” (with a nod to Python).

2 Likes

I forget where I heard it, but I think <- is supposed to kind of look like an epsilon in mathematics notation, meaning “element of” or “out of”. I would speak that as “for n out of one-two-three, do n times n”.

I do like “from” also because it keeps with the semantic meaning rather than the literal symbols.

4 Likes

∈ is \in in LaTeX. So I would pronounce <- as “in”.

1 Like

Learn You Some Erlang: List Comprehensions uses “in” - and it does set up the association between ∈ and <- though it isn’t explicit about. Personally I’ve always pronounced ∈ as “element of”.

Designing for Scalability with Erlang/OTP p.27

The effect of this is to successively bind the variable X to the values 2, 3, 5, 7, and 11. In other words, it generates the elements from the list: the symbol <- is meant to suggest the “element of” symbol for sets, ∈.

Erlang Programming - A Concurrent Approach to Software Development p.198

Generators
A generator has the form Pattern <- List, where Pattern is a pattern that is matched with elements from the List expression. You can read the symbol <- as “comes from”; it’s also like the mathematical symbol ∈, meaning “is an element of”.

3 Likes

I use in or into. That does also works for with use of it.

“from” sounds like a great idea!

1 Like

“Comes from” makes sense… though it makes me think of the COMEFROM command (https://en.wikipedia.org/wiki/COMEFROM). :wink:

“in” makes some sense to me (especially as I’ve done Python before), but IMHO “into” seems to make the information flow backwards – it’s coming out of the “supply” (or whatever you call the thing on the right side). Also it could be conflated with the into keyword one can use (when putting the results into: a string or map or whatever).

As for with, I’m not very familiar with it (still scratching the surface of Elixir here, and as it’s a liquid it keep filling up the scratch ;-)), but I’ve just finally read up on that a bit. (Saw https://elixirschool.com/lessons/basics/control-structures/, as pointed to by https://www.dailydrip.com/topics/elixir/drips/elixir-weekly-drip-2-and-exercise-reverse-polish-notation-calculator.) This time it seems to me like “from” and “out of” would be good, or “coming from”, and “in” might do, but again “into” seems exactly backwards to me. Using their example, I’d pronounce:

with {:ok, first} <- Map.fetch(user, :first),
{:ok, last} <- Map.fetch(user, :last),
do: last <> ", " <> first

as “with ok first from Map.fetch user first, [and] ok last from Map.fetch user last, do last append comma append first”. By contrast, methinks someone hearing it would have a harder time grokking “with ok first into Map.fetch user first, [and] ok last into Map.fetch user last, do last append comma append first”.

Perhaps you don’t mean what I think you mean, or maybe I’m not yet understanding with?

I’m for the pragmatic and unambigous pronounciation: “left-arrow” or “lesser-than and minus”. This version of pronounciation can’t be confused with others and also one doesn’t need to know about the surrounding context.

1 Like

According the Urbit Hoon glyph and character specification, <- could be pronounced as galhep. :sweat_smile:

3 Likes

in is probably closer to what i mean. into come from my mathematical thinking, which means to me that the result on the left is a subset of what is on the right. But it may just be a bad translation on how it works in French Maths Jargon.

1 Like

Hehe, I look Hoon, even written a couple simple things in it. ^.^;

I think the main issue with <- is it is used in different ways in two different contexts, as an ‘for each element’ in for and a ‘match’ in with, which I find odd since = is already match. That is the major oddity source for me. ^.^;

Haskell uses “draw” or “draws” to reference <- in list comprehensions, which are a very similar syntactic construct to comprehensions in Elixir. I find myself using “from” sometimes as well, particularly when speaking about with expressions.

It might be useful to rule out language that references other operators, keywords, or common arguments. in, into, elem, match would be easy to confuse

I’ve just discovered a context, which may be somewhat common, where pronouncing it as “from” may be somewhat of a clash. I’ve just started reading the Elixir School page on OTP Concurrency (https://elixirschool.com/lessons/advanced/otp-concurrency/) and am wondering, is it a common idiom (or just theirs) for a GenServer or similar thing, to refer to the sender of a request as from?

Yeah, it’s common.

It’s a typespec (GenServer.from/1) for a parameter of the callback GenServer.handel_call/3.

Ironically it’s supposed to be opaque - Designing for Scalability with Erlang/OTP p. 89

Always use From as an opaque data type; don’t assume it is a tuple, as its representation might change in future releases.

I don’t think that’s true. It’s documented as {pid(), Tag} in erlang docs - there’s even this fragment:

From is a tuple {Pid,Tag}, where Pid is the pid of the client and Tag is a unique tag.

While I agree that any “opaque”-ness should be called out in the documentation, I suspect that Cesarini/Vinoski are after a different sort of “off-limits”-ness:

  • the From type is produced by OTP expressly for the purpose of consumption by OTP (e.g. gen_server:reply/2). So:
  • Don’t go off making your own {pid(),Tag} tuples and feed them to OTP. Just because you may be able to get that approach to work now - future OTP releases could break the code (e.g. some logic that previously ignored the tag may start making decisions based on it).
  • Don’t rely on any information inside the From type - e.g. if the processing logic needs a pid to reply to, do not get it from the From argument but include it explicitly in the request message for use by the processing logic.
  • Any instance of a From type only has a very limited window of usefulness because of the tag acting as a correlation identifier. So once the call request has been replied to, the From instance should be discarded.

These two contexts could be considered similar by noting that both are in fact monadic constructs. Although Elixir does not (yet… :smiling_imp:) expose general monadic coding possibilities to the users (there are some libraries that do though), I think this issm where the <--syntax comes from.

Hmm, that is true, though the language does not explicitly use monads anywhere it does use them very implicitly…