
History of Erlang and Elixir - factandfiction
https://medium.com/@Serokell/history-of-erlang-and-elixir-ab54415dbf9a
======
EdwardDiego
Argh. Odd statements about "Erlang was implemented in Prolog, therefore, it's
an FP language" aside, I was interested to read more on Elixir's meta-
programming, and was assured that this code was a great example[1]. But there
was no further discussion, just a Github link.

For anyone else wondering the same, the Elixir docs give more insight into
quote/unquote[2]...

...but I'm still unsure as to why the Unicode code uses it. Most of the time
it's unquoting byte_size - but why does what looks like a function call need
to be unquoted?

It looks like it's defining the same function with different pattern matching
clauses using it, e.g.,

    
    
      for codepoint <- cluster["CR"] ++ cluster["LF"] ++ cluster["Control"] do
        def next_grapheme_size(<<unquote(codepoint), rest::binary>>) do
          {unquote(byte_size(codepoint)), rest}
        end
      end
    

Would define next_grapheme_size with an arg pattern that matches each code
point, effectively creating a pattern match switch without boilerplating it? I
think? Keen to hear from someone who knows Elixir.

But yeah, some more detail on a) what it's doing and b) why it's awesome
would've been nice.

[1]: [https://github.com/elixir-
lang/elixir/blob/0d32ea6bc4bcbd626...](https://github.com/elixir-
lang/elixir/blob/0d32ea6bc4bcbd626de98b2e2b493a42a4423992/lib/elixir/unicode/unicode.ex)
[2]: [https://elixir-lang.org/getting-started/meta/quote-and-
unquo...](https://elixir-lang.org/getting-started/meta/quote-and-unquote.html)

~~~
elevader
The unquote in your code example doesn't necessarily _need_ to be unquoted, it
would be enough to unquote the codepoint variable here. The point, I guess, is
about at what point you want to evaluate the code. There is a great little
function called Macro.to_string that might make this more clear:

    
    
      Macro.to_string(quote do: length([1,2,3]))

will return "length([1,2,3])", so it basically creates a macro that, if
included in some code, will calculate the length of the list [1,2,3] at
_runtime_.

    
    
      Macro.to_string(quote do: unquote(length([1,2,3])))

will return "3" instead, it basically executes the length function at _compile
time_ and then the macro will simply return that if called.

So the code example you provided basically calculates the byte size at compile
time and will then only return static results at runtime.

~~~
EdwardDiego
Thanks! That makes it clearer. So presumably the for loop it's nested in is
also evaluated at compile time?

~~~
elevader
Yes, exactly. This code basically runs at compile time and creates functions
that return static results. This case doesn't have to be wrapped inside of the
quote thing (I'm not even sure if it would compile if you did...), which is
somewhat confusing in my opinion.

------
conradfr
Not a bad article but Phoenix is not "hands down the best web development
framework that is out there".

It's quite great at what it does, and it's obviously technically well done,
but it's also very not "battery included" so you have to shop around for a lot
of things like Authentification/Authorization, i18n etc.

Also templating feels a bit old school. After using extends and blocks with
Jinja2 and Twig the "layout that includes your action view" model feels so
rigid and limited. It seems you can use render_existing/3 that would be
equivalent to content_for in Rails but that's not that obvious to me

It's unfortunate because LiveView puts back server-side rendering on the map
and it's exciting.

~~~
regulation_d
I personally like that Phoenix is kind of a middleweight framework, but at
least one of batteries you mentioned as missing is being addressed. José is
working on an authentication solution built into Phoenix.

~~~
beckler
Authentication is hard, but to be honest, building your own authorization
framework is actually really easy in phoenix. Mine is about 80 LOC, and most
of it came from the phauxth generator. Granted the default is rather broad, so
I've added a few functions to handle some role specific stuff.

------
zapttt
elixir is npm for erl.

the single example you need to know to snub it:

    
    
       x = 1
       x = 2
    

thats valid elixir. you're better off using javascript or php at this point

~~~
hmmokidk
that's valid javascript (it's also very dangerous javascript)... and would be
valid php if you sandwich it between a $ and a ;

elixir is not npm for erlang, hex is more like npm.

~~~
zapttt
elixir is mix. mix is hex.

hence elixir is npm for erlang

