<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brujo Benavides</title>
    <description>The latest articles on DEV Community by Brujo Benavides (@elbrujohalcon).</description>
    <link>https://dev.to/elbrujohalcon</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F13894%2F561b7cf7-c159-4d38-8125-31ca8a4393dc.JPG</url>
      <title>DEV Community: Brujo Benavides</title>
      <link>https://dev.to/elbrujohalcon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/elbrujohalcon"/>
    <language>en</language>
    <item>
      <title>Aaargh!! - Macros, Parse Transforms and others @ Erlang Battleground</title>
      <dc:creator>Brujo Benavides</dc:creator>
      <pubDate>Mon, 10 Apr 2017 17:33:41 +0000</pubDate>
      <link>https://dev.to/elbrujohalcon/aaargh---macros-parse-transforms-and-others--erlang-battleground</link>
      <guid>https://dev.to/elbrujohalcon/aaargh---macros-parse-transforms-and-others--erlang-battleground</guid>
      <description>&lt;p&gt;Not so long ago, &lt;a href="https://twitter.com/rjmh?lang=es"&gt;John Hughes&lt;/a&gt; presented a module called &lt;em&gt;Aaargh!!&lt;/em&gt; to the &lt;a href="http://erlang.org/pipermail/erlang-questions/2017-January/091550.html"&gt;erlang-questions&lt;/a&gt; mailing list. He showed how parse transforms, macros and the Erlang compiler all worked together to mess up with us a bit. I’ll just present that very same story here. If you have read it already, you can safely skip the rest of the article.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Weird Module
&lt;/h2&gt;

&lt;p&gt;This is basically the module that John sent to the mailing list (I changed its name just so it’s easier to avoid the apostrophes)…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weird&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;PLEASE_DONT&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;ifdnef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;PLEASE_DONT&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="n"&gt;parse_transform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;undefined_parse_transform&lt;/span&gt;&lt;span class="p"&gt;}).&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;endif&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The idea is that we first define the &lt;code&gt;PLEASE_DONT&lt;/code&gt; macro in a line that we can later comment out if needed (or rather remove and define the macro at compile time).&lt;/p&gt;

&lt;p&gt;Then, if the macro is &lt;strong&gt;not&lt;/strong&gt; defined, we run the code through a parse transformation called &lt;code&gt;undefined_parse_transform&lt;/code&gt;. The key point here is that this parse transformation module doesn’t exist, so this line &lt;em&gt;should&lt;/em&gt; &lt;em&gt;not compile&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;But the macro &lt;em&gt;is&lt;/em&gt; defined, so the parse transform should not be used, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nv"&gt;$ &lt;/span&gt;erlc weird.erl
    src/weird.erl: undefined parse transform &lt;span class="s1"&gt;'undefined_parse_transform'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  And My Macro?
&lt;/h2&gt;

&lt;p&gt;Turns out that macro is &lt;strong&gt;not&lt;/strong&gt; defined. As Alex points out in the mailing list…&lt;/p&gt;

&lt;blockquote&gt;
&lt;h1&gt;
  
  
  there’s no one-argument define()
&lt;/h1&gt;
&lt;/blockquote&gt;

&lt;p&gt;As you can see in &lt;a href="http://erlang.org/doc/reference_manual/macros.html#id85572"&gt;the docs&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A macro is defined as follows:&lt;br&gt;
&lt;em&gt;-define(Const, Replacement).&lt;br&gt;
-define(Func(Var1,...,VarN), Replacement).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If we change the define line in our code…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weird&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;PLEASE_DONT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;true&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;ifndef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;PLEASE_DONT&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="n"&gt;parse_transform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;undefined_parse_transform&lt;/span&gt;&lt;span class="p"&gt;}).&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;endif&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…it compiles perfectly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nv"&gt;$ &lt;/span&gt;erlc weird.erl
    &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls &lt;/span&gt;weird.beam
    weird.beam
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why didn’t you tell me so?
&lt;/h2&gt;

&lt;p&gt;That’s it, right? Well… not so easy. If there is no one-argument define(), then why did the compiler/parser not warned us about it. Check this out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weird&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;PLEASE_DONT&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we try to compile that module…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nv"&gt;$ &lt;/span&gt;erlc weird.erl
    src/weird.erl:3: badly formed &lt;span class="s1"&gt;'define'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What’s going on here?
&lt;/h2&gt;

&lt;p&gt;What we have here are two different kinds of &lt;em&gt;compilation&lt;/em&gt; errors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;badly formed ‘define’ attributes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;inexistent parse transformations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We only see one of them because they are found in different stages of the compilation process. To understand this a little bit better you’ll find a video of a talk by &lt;a href="https://medium.com/@carlsson.richard"&gt;Richard Carlsson&lt;/a&gt; that deals with the compiler and its friends in a lot of detail below. But in a nutshell: For the &lt;em&gt;parser&lt;/em&gt;, one-argument defines (or any other attribute declarations, for what is worth) are perfectly valid even when it does recognize macro definitions, but missing parse transformation modules are not. The &lt;em&gt;compiler&lt;/em&gt; is the one that detects one-argument defines as errors. The &lt;em&gt;parser&lt;/em&gt; is executed before the &lt;em&gt;compiler&lt;/em&gt; and between those two, only the first one that finds an error, gets to shout about it ;)&lt;/p&gt;

&lt;p&gt;That’s why when the define is broken, the &lt;em&gt;parser&lt;/em&gt; ignores it and proceeds until it finds a missing parse transformation module and then it emits the error and stops the process. But when the parser finds no problems (i.e. there is no missing parse transformation module, in our case), then the &lt;em&gt;compiler&lt;/em&gt; is executed, it finds the one-argument define and fails.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bonus Track
&lt;/h2&gt;

&lt;p&gt;After this whole conversation in erlang-question there was just one extra question in my mind:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If there’s no one-argument define(), what happens if I define a macro in the command line, then?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To test that, I created this module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weird&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;macro&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;

    &lt;span class="nf"&gt;macro&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="nv"&gt;THE_MACRO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I can totally compile the module and specify a value for the macro on command line, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nv"&gt;$ &lt;/span&gt;erlc &lt;span class="nt"&gt;-DTHE_MACRO&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;hello weird.erl
    &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I try to use it in an Erlang shell, I get the following expected result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;weird&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;macro&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="n"&gt;hello&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, what happens if I don’t specify a value for the macro? &lt;a href="http://erlang.org/doc/man/erlc.html#id200346"&gt;The docs&lt;/a&gt; are a little vague in this area&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;-D&lt;br&gt;
 Defines a macro.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s try ourselves, shall we?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nv"&gt;$ &lt;/span&gt;erlc &lt;span class="nt"&gt;-DTHE_MACRO&lt;/span&gt; weird.erl
    &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the module did compile, the Erlang compiler should’ve assigned a value to the macro, right? Let’s see what that value is…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;weird&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;macro&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="n"&gt;true&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---DKSUjVG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/http://i0.kym-cdn.com/photos/images/newsfeed/000/617/851/56d.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---DKSUjVG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/http://i0.kym-cdn.com/photos/images/newsfeed/000/617/851/56d.gif" alt="I don’t know what I expected" width="500" height="288"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article was originally published in &lt;a href="https://medium.com/erlang-battleground/aaargh-a7dc940f8d0f"&gt;Medium&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>erlang</category>
      <category>compilers</category>
    </item>
    <item>
      <title>Unbalanced Parentheses</title>
      <dc:creator>Brujo Benavides</dc:creator>
      <pubDate>Wed, 05 Apr 2017 02:38:34 +0000</pubDate>
      <link>https://dev.to/elbrujohalcon/unbalanced-parentheses</link>
      <guid>https://dev.to/elbrujohalcon/unbalanced-parentheses</guid>
      <description>&lt;h2&gt;
  
  
  …or another reason not to use macros
&lt;/h2&gt;

&lt;p&gt;This is an article about something I showed &lt;em&gt;live&lt;/em&gt; at the &lt;a href="http://www.erlangelixir.com/brujo-benavides.html"&gt;Erlang &amp;amp; Elixir Factory San Francisco 2017&lt;/a&gt;. It’s about what you can and can not do if you are fancy with your module attributes in Erlang.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TV-ldFkI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ArcTFoMlMmoqJS3ZfU1-f7Q.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TV-ldFkI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ArcTFoMlMmoqJS3ZfU1-f7Q.jpeg" alt="Golden Gate Park, from GrandView Park, SF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Notes
&lt;/h3&gt;

&lt;p&gt;First of all, &lt;a href="https://medium.com/@unbalancedparen"&gt;Federico&lt;/a&gt;: sorry for stealing your name. It was just too cool not to ;)&lt;br&gt;
That said, here is the video of the whole talk, in case you want to watch it…&lt;/p&gt;



&lt;p&gt;And if you prefer Spanish…&lt;/p&gt;



&lt;p&gt;Ok, enough with the links! Let’s get down to business…&lt;/p&gt;


&lt;h3&gt;
  
  
  The Usual Suspects
&lt;/h3&gt;

&lt;p&gt;This is a perfectly valid Erlang module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;whoami&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can compile it and execute its function…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="n"&gt;my_mod&lt;/span&gt;
    &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is also a perfectly valid Erlang module (now using a macro):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;whoami&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="nv"&gt;MODULE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As expected, same results…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="n"&gt;my_mod&lt;/span&gt;
    &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  The Cool Guy
&lt;/h3&gt;

&lt;p&gt;But… that &lt;strong&gt;spec&lt;/strong&gt; attribute there has no parentheses around it. Can we also remove the parentheses around the other attributes? The &lt;a href="http://erlang.org/doc/reference_manual/modules.html#id77415"&gt;docs&lt;/a&gt; are not very clear about that. They show the following general syntax for attributes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt;T&lt;/span&gt;&lt;span class="ni"&gt;ag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But then there are attributes like &lt;em&gt;spec&lt;/em&gt;, &lt;em&gt;type&lt;/em&gt; or &lt;em&gt;callback&lt;/em&gt; that are shown without parentheses. So, why not give it a try? How much nicer would that export be without the parentheses around the brackets, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;export&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;whoami&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It actually works!! Look at that…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="n"&gt;my_mod&lt;/span&gt;
    &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8TJL11oz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2A0NffgULjv2vhlMlhpc4xCg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8TJL11oz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2A0NffgULjv2vhlMlhpc4xCg.gif" alt="YEY!! (from Primo GIF)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m not writing a parentheses there anymore!&lt;/p&gt;




&lt;h3&gt;
  
  
  Not so Fast, Cowboy!
&lt;/h3&gt;

&lt;p&gt;Well… I’m not a fan of macros, but sometimes I end up using the predefined ones, like I did with &lt;em&gt;?MODULE *above&lt;/em&gt;…*&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;export&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;whoami&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;

    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
    &lt;span class="nf"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="nv"&gt;MODULE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you try to compile that module, you’ll find quite an unexpected result…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;
    &lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;erl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
    &lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;erl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;whoami&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="n"&gt;undefined&lt;/span&gt;
    &lt;span class="n"&gt;my_mod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;erl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="n"&gt;for&lt;/span&gt; &lt;span class="n"&gt;undefined&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;whoami&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OpgIL6q9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1200/1%2AqOekxkFDrnQQIekBjkouiQ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OpgIL6q9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1200/1%2AqOekxkFDrnQQIekBjkouiQ.gif" alt="WAT (from Primo GIF)"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  What’s going on here?
&lt;/h3&gt;

&lt;p&gt;This time I literally have no clue. I can see that, in order to use the macro &lt;em&gt;?MODULE&lt;/em&gt; you have to use parentheses around your module name. But I haven’t done any research to find the root cause of it. That’s mostly because I have a very distinctive feeling that it will take me to the land of parsers, compilers, etc. and that’s a place I like to stay away from.&lt;/p&gt;

&lt;p&gt;So, for this article, dear reader, if you are brave enough to go deep into the realm of the Erlang compiler and its friends and find out what’s going on, please let me know in the comments below.&lt;/p&gt;

&lt;p&gt;And of course, if you can go ahead and fix this by sending a Pull Request to &lt;a href="https://github.com/erlang/otp"&gt;erlang/otp&lt;/a&gt;…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BZ2ibUyN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AcB1elrj2xoC7XFZZ_XnrVQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BZ2ibUyN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AcB1elrj2xoC7XFZZ_XnrVQ.jpeg" alt="Office Space (1999)"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;This article was first published in &lt;a href="https://medium.com/erlang-battleground"&gt;&lt;em&gt;Erlang Battleground&lt;/em&gt;&lt;/a&gt; as &lt;a href="https://medium.com/erlang-battleground/unbalanced-parentheses-6634140c6adb"&gt;&lt;strong&gt;Unbalanced Parentheses&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>erlang</category>
      <category>compilers</category>
    </item>
    <item>
      <title>Hi, I'm Brujo Benavides</title>
      <dc:creator>Brujo Benavides</dc:creator>
      <pubDate>Tue, 28 Mar 2017 16:24:29 +0000</pubDate>
      <link>https://dev.to/elbrujohalcon/hi-im-brujo-benavides</link>
      <guid>https://dev.to/elbrujohalcon/hi-im-brujo-benavides</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6mv0o7lfyernzrcqbdoa.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6mv0o7lfyernzrcqbdoa.JPG" alt="This is me" width="800" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have been coding for 25 years.&lt;/p&gt;

&lt;p&gt;You can find me everywhere (e.g. Twitter, Github, etc.) as &lt;a href="https://twitter.com/elbrujohalcon" rel="noopener noreferrer"&gt;@elbrujohalcon&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Buenos Aires, Argentina.&lt;/p&gt;

&lt;p&gt;I'm Inaka's CTO and Erlang Solutions' Tech Lead and Erlang Trainer.&lt;/p&gt;

&lt;p&gt;I mostly program in Erlang, but I am currently learning more about Elixir.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
