When building timex 1.0.0-rc3 with current elixir master the following compilation error occurs:
== Compilation error on file lib/date/date_format.ex ==
** (ArgumentError) defdelegate/2 only accepts variable names, got: %DateTime{} = date
(elixir) lib/kernel/utils.ex:47: Kernel.Utils.check_defdelegate_args/1
(elixir) lib/kernel/utils.ex:25: Kernel.Utils.defdelegate/2
lib/date/date_format.ex:22: anonymous fn/3 in :elixir_compiler_4.__MODULE__/1
(elixir) lib/enum.ex:1477: Enum."-reduce/3-lists^foldl/2-0-"/3
lib/date/date_format.ex:22: (module)
See here for the respective line in the timex: https://github.com/bitwalker/timex/blob/1.0.0-rc3/lib/date/date_format.ex#L22
The problem here is that defdelegate/2 doesn't accept match clauses anymore (since 68b4259d). I guess match clauses should still be accepted, however, and check_defdelegate_args/1 is a bit too strict.
What do you think?
I don't think we should support it in delegate but it is a breaking change, so we need to fix it. :) Thanks.
@josevalim whoops, should I revert it back to checking only for default args with \\?
No worries. I have already a fix, I will push it soon :)
On Wednesday, November 25, 2015, Andrea Leopardi [email protected]
wrote:
@josevalim https://github.com/josevalim whoops, should I revert it back
to checking only for default args with ?—
Reply to this email directly or view it on GitHub
https://github.com/elixir-lang/elixir/issues/3994#issuecomment-159731186
.
_José Valimwww.plataformatec.com.br
http://www.plataformatec.com.br/Founder and Director of R&D_
Is there an issue backing the decision to drop support for patterns in defdelegate?
@alco I think none except that delegation is not the place to apply patterns.
What if you have a series of functions in a module,
def example(:clause_one, arg), do: "one"
def example(:clause_two, arg), do: "two"
and at the bottom you want to do something like
defdelegate example(default, arg), to: DefaultHandler
The philosophy here is that your module implements some functions of the same arity as those of another module, perhaps for something like a state machine, but you still want to default to the other module in the case that none of your clauses matched.
Of course one could use macros and defoverridable, but debugging __using__ is a pain in VSCode (I don't know about other IDEs) because the error is show to happen where the macro is applied, and no errors are highlighted within the macro's quote block itself.
And of course you can also just require the module and do def example(default, arg), do: DefaultHandler.example(default, arg), but then I'm a little confused as to the purpose of defdelegate other than as a syntactical shortcut.
I landed here through google search.
Context... I am bulk importing city related data, data is not uniform, some cities have different kind of data, need to processing differently.

I wish there was pattern matching, so I dont need to retype the same argument again (less code, less bugs).
For now writing argument twice works.
There must be a better way if someone else knows.
You can bind the parameter to avoid duplicating the code:
defp process(%{...} = arg) do
PuneImporter.import(arg)
end
Most helpful comment
You can bind the parameter to avoid duplicating the code: