Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Metaprogramming in Elixir

Nando Sousa
November 11, 2017

Metaprogramming in Elixir

Brief introduction to metaprogramming using Elixir presented at Elixir day 1st edition in Florianópolis-Brazil.

Video: (pt-BR)
https://www.youtube.com/watch?v=RiEifnTo5d0&feature=youtu.be&t=120s

Nando Sousa

November 11, 2017
Tweet

More Decks by Nando Sousa

Other Decks in Technology

Transcript

  1. Resultados Digitais: We're hiring! ECTO def unpublished_by_title(title) do from p

    in Post, where: is_nil(p.published_at) and fragment("lower(?)", p.title) == ^title end
  2. Resultados Digitais: We're hiring! Phoenix - Router defmodule Dummy.Router do

    … scope "/", Dummy do pipe_through :browser get "/", PageController, :index end … end
  3. Resultados Digitais: We're hiring! Bot example defmodule Bot.Vocabularies.Finance do use

    Bot.Vocabulary @help "show all accounts balance" command "balance" do reply parsed_balances end end
  4. Resultados Digitais: We're hiring! AST - example {:+, [context: Elixir,

    import: Kernel], [1, {:*, [context: Elixir, import: Kernel], [1,5]]} (+ 1 (* 1 5)) (+ 1 5) 1
  5. Resultados Digitais: We're hiring! Macros defmodule MyModule do def my_method(first_arg)

    do if first_arg == "balance" do call_another_function end first_arg end end