Skip to content

Instantly share code, notes, and snippets.

@h4cc
Last active March 25, 2024 13:00
Show Gist options
  • Save h4cc/8655591 to your computer and use it in GitHub Desktop.
Save h4cc/8655591 to your computer and use it in GitHub Desktop.
All symbols used in the elixir programming language

Symbols used in Elixir

A list of all not symbols and notations of elixir. Tried to have a base for comparision for other programming languages.

Operators

  • === (strict)
  • !== (strict)
  • == (relaxed)
  • !=
  • &&
  • ||
  • !
  • , >=, <, <=

  • +, -, *, /, div, rem
  • <> (binary concat)
  • ++ (list concat)
  • -- (list diff)

Types

  • :foo (atom)
  • {1, 2} (tple)
  • [1, 2, 3] (list)
  • [1 | [2, 3]]
  • [a: 1, b: 2] (keyword 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_
@kiru
Copy link

kiru commented Apr 20, 2022

@map_name %{ a: 1, b: 2} , what is @ symbol
Constants, as seen here: https://elixir-lang.org/getting-started/module-attributes.html#as-constants

@jakespracher
Copy link

jakespracher commented Jan 11, 2023

Would be helpful to link to an explanation of &module.function/arity

Seems like this is a good reference https://elixir-lang.org/getting-started/modules-and-functions.html#function-capturing

@Linford241
Copy link

Please how can remove characters from a string in elixir

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