elixir - Why are pin operators necessary in Ecto queries? -


in elixir, pin operator used prevent variable rebinding. however, regard ecto query like

from u in user, where: u.username == ^username 

the authors of programming phoenix state (in chapter 7) that

remember, ^ operator (called pin operator) means want keep ^username same.

but doesn't sound right, because apparently, comparison in query shall not cause rebinding of variables.

are authors of book (which josé valim co-authored) mistaken? pin operator in ecto queries merely construct of ecto dsl instead of usual elixir pin operator? or query chance rebind username after macros expanded?

ecto's queries rely on macros provide powerful dsl use. means that, whatever comes after from, not "regular" elixir code, dsl transformed sql query. so, caret there not pin operator per se, , has nothing pattern matching (although still can called "pin operator" because people forget words such caret , ampersand , asterisk). it's convenient operator ecto's authors choose "interpolation operator". without it, username example taken literally, , inserted directly generated sql (though ecto smart enough see that's not want spills error).

great question btw, inspired me read more macros (newbie in fp here).


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -