Three stupid questions

211 views
Skip to first unread message

Dmitrii Dimandt

unread,
Aug 18, 2015, 2:48:24 PM8/18/15
to elixir-lang-talk
Hi all

I have three potentially stupid questions totally unrelated to each other.


1. Macro names


So, the questions still stand: what can we set as macro names, and how to define operators? :)

2. Syntax inconsistency

I realize that "I should've read the docs and the source and understood metaprogramming better", but still...

I've learned to live with the fact that

    f(a, b), do: function_body

but

    f(a, b) do
      function_body
    end

(no comma, no colon in the second case) What I still don't understand is why, for instance, some stuff breaks the convention:

quote do: one_liner
quote do
  multiple_lines
end

to show it together:

    defmacro zz(a), do: quote do: unquote a

This makes me consistently keep track of commas, colons and keep in mind what I'm dealing with: one-liners? multi-liners? macros? any combination of those?

3. Filename extension inconsistency

All files are *.ex, and mix compile will only compile *.ex
mix test requires files to have a .exs extension, and won't even look at *.ex

Why? This caused me a couple of grey hairs when I couldn't understand why mix test wouldn't pick up my newly written tests. mix test path/to/file works perfectly though.

Please, don't kill me :)

Jason M Barnes

unread,
Aug 18, 2015, 3:21:02 PM8/18/15
to elixir-l...@googlegroups.com
I don’t know the answer to the first one, but I’ll try to answer the other two inline:

On Tue, Aug 18, 2015 at 2:48 PM, Dmitrii Dimandt <dmi...@dmitriid.com> wrote:
2. Syntax inconsistency


The “do:” part is part of a Keyword list so the comma separates the arguments from the beginning of the Keyword list.

def f(a, b), do: stuff

The comma and colon can be removed due to syntactic sugar:

def f(a, b) do
  stuff
end

“do” is just a special keyword that allows this.  “else” is the same:

if (foo), do: bar, else: baz
if (foo) do
  bar
else
  baz
end

Notice in this example, you can see both keywords used in the Keyword list.

In the case of “quote” notice that there are no arguments, so the Keyword list is the first item:

quote do: stuff

No need for a comma.  But the syntactic sugar still applies — removing the colon:

quote do
  stuff
end
 

3. Filename extension inconsistency


It is just a convention that mix follows.  *.ex is for files that are intended to be compiled.  *.exs is for files that are intended to be run without being compiled.

Jason 

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/293c65da-ceb1-4359-a512-40692615cea9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dmitrii Dimandt

unread,
Aug 18, 2015, 4:01:27 PM8/18/15
to elixir-l...@googlegroups.com
The “do:” part is part of a Keyword list so the comma separates the arguments from the beginning of the Keyword list.

def f(a, b), do: stuff


Aha. Now it makes sense :)
 

3. Filename extension inconsistency


It is just a convention that mix follows.  *.ex is for files that are intended to be compiled.  *.exs is for files that are intended to be run without being compiled.

Aha, now it also makes sense. Kinda :)


Thank you! 

Onorio Catenacci

unread,
Aug 18, 2015, 4:46:43 PM8/18/15
to elixir-lang-talk
I had an old friend--an older developer.  He was fond of calling things "Conscious Design Decisions"--that is, when a developer could take one path or another (e. g. pick up all .ex* files or just pick up .exs files) and the developer took a path that seemed somehow inappropriate to later developers he'd say "CDD".  

I mean to say that it's true that upon reflection one might decide that we'd rather have it pick up all files in the test directory regardless of extension.  But when it was being built someone had to decide that issue and he decided to pick that convention.  

I feel confident that if we changed mix to pick up both .ex and .exs in the test directory, someone would come along and say "why does the directory have to be called 'test'"?  :)

--
Onorio

eksperimental

unread,
Aug 19, 2015, 2:54:27 AM8/19/15
to elixir-l...@googlegroups.com
I don't know the real reason behind it, but to me its a feature that
allows us to run the test really quick without the need to wait for the
compilation.
Test are mean to run only once, just when you need to see if you code
passes all the test and that's it.
> >>> <https://groups.google.com/d/msgid/elixir-lang-talk/293c65da-ceb1-4359-a512-40692615cea9%40googlegroups.com?utm_medium=email&utm_source=footer>

Dmitrii Dimandt

unread,
Aug 19, 2015, 4:13:16 AM8/19/15
to elixir-l...@googlegroups.com
I feel confident that if we changed mix to pick up both .ex and .exs in the test directory, someone would come along and say "why does the directory have to be called 'test'"?  :)


Sorry, but that is so wrong. 

Dmitrii Dimandt

unread,
Aug 19, 2015, 4:15:39 AM8/19/15
to elixir-l...@googlegroups.com
On Wed, Aug 19, 2015 at 8:54 AM eksperimental <eksper...@autistici.org> wrote:
I don't know the real reason behind it, but to me its a feature that
allows us to run the test really quick without the need to wait for the
compilation.
Test are mean to run only once, just when you need to see if you code
passes all the test and that's it.


Then it's enough for mix to skip the test directory in the `mix compile` target . It would make much more sense than "hey, here we have Elixir code. It looks exactly the same as this other Elixir code, but it has to have a different file extension for some reason" ;)

Chris McGrath

unread,
Aug 19, 2015, 4:19:11 AM8/19/15
to elixir-l...@googlegroups.com
.exs files are compiled, just in memory and no beam file is output. So I see .ex files as containing code that needs to ship with your application for it to work, and .exs files as containing code that doesn’t.

.exs files are also handy when you’re trying something out and don’t want to have to clean up a load of beam files afterwards.

Chris
> --
> You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/20150819135412.7f1cbf29.eksperimental%40autistici.org.
signature.asc
Reply all
Reply to author
Forward
0 new messages