Skip to content

Instantly share code, notes, and snippets.

@gertcuykens
Forked from h4cc/elixir_symbols.md
Last active March 6, 2021 17:20
Show Gist options
  • Save gertcuykens/55a1cc4037223f986248da8f42cfa7b1 to your computer and use it in GitHub Desktop.
Save gertcuykens/55a1cc4037223f986248da8f42cfa7b1 to your computer and use it in GitHub Desktop.
All symbols used in the elixir programming language

Symbols used in Elixir

https://hexdocs.pm/elixir/Kernel.html

Operators

  • === (strict)
  • !== (strict)
  • == (relaxed)
  • !=
  • &&
  • ||
  • !
  • >, >=, <, <=
  • +, -, *, /, div, rem
  • <> (binary concat)
  • ++ (list concat)
  • -- (list diff)

Types

  • 1 (integer)
  • 0x1F (integer)
  • 1.0 (float)
  • true (boolean)
  • :foo (atom)
  • {1, 2} (tple)
  • [1, 2, 3] (list)
  • [1 | [2, 3]]
  • [a: 1, b: 2] (keyword list)
  • [65, 66] or 'AB' (integer list)
  • << 65, 66 >> or "AB" (binary string)
  • 1..9 (range)

Functions

  • fn params [guard] -> body end
  • function do params [guard] -> body end
  • func.() (calling a anonymous function from a variable)
  • &(&1, &2) (closure shortcut)
  • def name(params) [guard] do expression end
  • def name(params) [guard], do: expression
  • parameter \\ 42 (default parameter)
  • defp ... (private function)
  • &module.function/arity
  • defmodule ...
  • require ...
  • use ...
  • import Module, only: foo, except: bar
  • alias Module, as: M
  • :erlang.function() (calling a erlang function)
  • when [guard] (pattern matching guard)

List Comprehensions

  • lc x inlist list, y inbits binary, x < y, do: ...
  • bc ... inbits ..., guard, do: ...

Control flow

  • something, do: ...
  • else, rescue, try, ensure
  • a |> b() (pipeline operator)
  • if expr do ... else ... end
  • condition do matcher -> expr end
  • case expr do matcher -> expr end

Regex and Sigils

  • %r{pattern]opts (regex)
  • %type{content} (sigil)

Messages

  • pid <- message (Sending message)
  • receive do matcher -> expression after 42 -> expression end

Constants

  • _MODULE_
  • _FILE_
  • _DIR_
  • _ENV_
  • _CALLER_

TODO

  • ^ : Use the pin operator ^ when you want to pattern match against an existing variable’s value rather than rebinding the variable

  • %{} : map

  • #{} in string : run

  • fun! : a function with error message

  • fun? : a boolean function

  • _ : default case

  • _foo : a variable not used

  • @proper : module attributes

  • | : %{recipe | salt: "2tsp"}

  • ? : return codepoint https://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment