Using parenthesis syntax in an Elixir record

I am learning Elixir programming with elixir lang, getting started , and I am stacked record brace syntax.

This is an example:

defrecord FileInfo, atime: nil, accesses: 0
defmodule FileAccess do
  def was_accessed?(FileInfo[accesses: 0]), do: false
  def was_accessed?(FileInfo[]),            do: true
end

So far, the author believes that Elixir extends the record to a tuple at compile time. so

def was_accessed?(FileInfo[accesses: 0]), do: false

matches with:

def was_accessed?({ FileInfo, _, 0 }), do: false

But when I enter the Elixir shell:

iex(13)> FileInfo[access: 0] == {FileInfo, nil, 0}
true
iex(14)> FileInfo[access: 0] == {FileInfo, 0, 2}
false

The result was FileInfo[access: 0] only equal {FileInfo, nil, 0},

no { FileInfo, _, 0 }.

What is the difference between these two scenes?

+4
source share
1 answer

Very good question!

- . Elixir , FileInfo[] ( , ), _.

, . _ :

iex> _
** (CompileError) iex:1: unbound variable _

Elixir .

+4

Source: https://habr.com/ru/post/1526500/


All Articles