@@ -573,7 +573,7 @@ defmodule Record do
573573 ## Function generation
574574
575575 # Define __record__/1 and __record__/2 as reflection functions
576- # that returns the record names and fields.
576+ # that return the record names and fields.
577577 #
578578 # Note that fields are *not* keywords. They are in the same
579579 # order as given as parameter and reflects the order of the
@@ -585,9 +585,26 @@ defmodule Record do
585585 #
586586 # FileInfo.__record__(:name) #=> FileInfo
587587 # FileInfo.__record__(:fields) #=> [atime: nil, mtime: nil]
588+ # FileInfo.__record__(:index, :atime) #=> 1
589+ # FileInfo.__record__(:index, :mtime) #=> 2
588590 #
589591 defp reflection(values) do
592+ quoted = lc { k, _ } inlist values do
593+ index = find_index(values, k, 0)
594+ quote do
595+ @doc false
596+ def __record__(:index, unquote(k)), do: unquote(index + 1)
597+ end
598+ end
599+
590600 quote do
601+ unquote(quoted)
602+
603+ @doc false
604+ def __record__(:index, _), do: nil
605+ @doc false
606+ def __record__(:index, arg, _), do: __record__(:index, arg)
607+
591608 @doc false
592609 def __record__(kind, _), do: __record__(kind)
593610
0 commit comments