Qqwy

Qqwy

TypeCheck Core Team

I stumbled across the following curious tidbit of how Elixir’s parser/compiler works:

defmodule Example do
  def {} do
    "Yes, this is allowed!"
  end
end
iex> Example.{}
"Yes, this is allowed!"

I cannot imagine any serious use-case for this, but it is curious.
I believe the cause is that :{} is a special atom that Elixir uses in its AST-definition to describe tuples with more than two elements.

Showing Posts 1 to 3

ityonemo

ityonemo

:rofl: My God, I want to use this for so many bad things that I promise to never make public ever.

henrik

henrik

Not the same, but here’s another fun one: How to "expect(…).to" in Elixir – The Pug Automatic

Qqwy

Qqwy OP

TypeCheck Core Team

It is impossible to import the Example module in this case, however, because that will make Elixir complain that you are attempting to override one of its special forms.

That said, it is possible to wrap any piece of Elixir AST in a macro that alters how the code that is passed to it is expanded. In this way you are able to alter even the behaviour of Elixir’s special forms.
One place where I’ve used this in the past is the Solution library, where the clauses of with and case-statements are overridden to have slightly extended support for tuples.
Another is e.g. the experiment I wrote late yesterday evening which allows bare captures to exist in pipes.


@henrik Thanks for sharing that piece of code! Tuple calls are indeed a strange historic artifact.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews