Fun with Metaprogramming

Recently I found out that you can get rather creative with Elixir’s metaprogramming as its AST lets itself be bent into some fancy shapes.

Use this stuff at your own peril! Don’t say I did not warn you. Your coworkers might lynch you… :smiling_imp: .

Ampersands

iex> use AtAt
iex> @@@@@@@@@@@@@@@@@@@@@@@self()
"Wow! Running self() with 23 ats!"
#PID<0.85.0>

Exclamation Marks:

iex(56)> import Scream

iex(58)> scream!! 42
"You say: 42."
iex(59)> scream!!!!!!!!!!!!!! 'I like trains and I cannot lie'
"You scream: 'I like trains and I cannot lie'!!"

Yes, these are definitely small party tricks, but I had to giggle a little, so I wanted to share these with you because maybe they make someone else giggle as well.
And who knows, maybe they can serve as some kind of inspiration to someone… :angel:

Do you guys know any other ways in which Elixir’s AST can be misused?

3 Likes

Hmm, my MLElixir project is a great big AST hack. ^.^

my two recent project:
1: https://github.com/cjen07/param_pipe
2: https://github.com/cjen07/prefix

2 Likes