small medium large xlarge

09 Nov 2015, 23:57
David Johnson (2 posts)

When compiling/using the file maps/derive.exs with Elixir 1.1 I see the error message:

** (ArgumentError) Access is not a protocol, cannot derive Access for Attendee
    (elixir) lib/protocol.ex:76: Protocol.assert_protocol!/2
    (elixir) lib/protocol.ex:591: Protocol.derive/5
    (stdlib) lists.erl:1337: :lists.foreach/2
    (elixir) lib/protocol.ex:579: Protocol.__derive__/3
    derive.exs:3: (module)

Apparently the Access protocol has been removed, what is the correct way to add the same behavior? I tried using the Access behaviour, however that requires that all of the methods be defined.

17 Nov 2015, 03:09
Andrew Feng (1 post)

Encountered the same issue here.

29 Nov 2015, 14:33
Dan Rees-Jones (2 posts)

This worked for me. I’m not sure if this is a good idea or anything though, as I don’t know enough about the reasons for deprecating the access protocol.

defmodule Attendee do @behaviour Access defstruct name: “”, over_18: false defdelegate [fetch(t, key), get_and_update(t, key, list)], to: Map end —

19 Dec 2015, 20:44
Jake Mays (1 post)

Also getting this error. As to the behaviour thing:

defmodule Attendee do
  @behaviour Access
  defstruct name: "", over_18: false

This is getting me the following warnings when compiled into iex:

$ iex maps/derive.exs
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

maps/derive.exs:1: warning: undefined behaviour function fetch/2 (for behaviour Access)
maps/derive.exs:1: warning: undefined behaviour function get_and_update/3 (for behaviour Access)
Interactive Elixir (1.1.1) - press Ctrl+C to exit (type h() ENTER for help)
10 Jan 2016, 17:08
Dave Thomas (366 posts)

The 1.2 version of the book addresses this.