我在尝试基于记录创建和ETS表时遇到了一个问题。代码取自Introducing Elixir一书。
以下是记录:
defmodule Planemo do
require Record
Record.defrecord :planemo, [name: nil, gravity: 0, diameter: 0, distance_from_sun: 0]
end现在,如果创建一个表,如下所示,它会成功:
planemo_table = :ets.new(:planemos,[:named_table, {:keypos, Planemo.planemo(:name) + 1}])在另一个示例中,作者使用以下语法(__record__),它失败了:
planemo_table = :ets.new(:planemos,[:named_table, {:keypos, Planemo.__record__(:index, :name) + 1}])错误:
** (UndefinedFunctionError) function Planemo.__record__/2 is undefined or private
Planemo.__record__(:index, :name)
planemo_storage.ex:6: PlanemoStorage.setup/0我最初认为也许__record__在Elixir 1.3.2中被弃用了,但我一直没有找到它的任何踪迹。请帮帮忙。
发布于 2016-08-10 20:48:07
那本书似乎很旧了。包括__record__在内的许多记录功能都是removed on 24 May 2014的,并且更改是Elixir 0.14 which was released on 17 June 2014的一部分。
https://stackoverflow.com/questions/38871763
复制相似问题