Write Your Own Sigil’s — Elixir Pro Coding.

Blackode
Blackode
Feb 22, 2017 · 4 min read
Image for post
Image for post
Photo by Donna on Unsplash

Sigil Overview

Sigil is a symbol or a letter which can do anything with the binary or a string that can be transformed to some complex format. You can create a magic with Sigil.

Keep your code simple and to be powerful.

Sigil Notation

sigil_x

Here x stands for the sigil letter.

Custom Sigils

You can build your own magical sigils of your choice. The only thing required is; you have to define functions in your module for each sigil.

Image for post
Image for post
Click to Zoom — Sigil Representation

Sigil Coding

Custom Sigil Implementation
def sigil_p binary, [] && def sigil_p binary, [?u]

Sigil Usage

$ iex my_sigils.ex
iex> import MySigils
MySigils
iex> ~p/user 123 delete/
"user/123/delete"
iex> ~p/medium.com blackode/
"https://www.medium.com/blackode"
Image for post
Image for post
Execution Screen Shot

Sigil documentation

We can also get the docs of the particular sigil by using the help function. If you want to look out p sigil documentation then, copy above lines of code into a file called my_sigils.ex and save. Now change your directory to where the file exists. Now compile the file with docs as

$ cd /path/to/file
$ elxirc my_sigils.ex
$ iex
iex> h MySigils.sigil_p
....................
documentation
.....................
Image for post
Image for post
https://t.me/blackoders
Image for post
if worth_clapping, do: “clap”, else: nil

blackode

Coding, thoughts, and ideas.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store