【问题标题】:Records in Erl (Erlang question)Erl 中的记录(Erlang 问题)
【发布时间】:2010-11-26 01:14:44
【问题描述】:

有没有办法直接在erl中使用记录?无论我尝试什么,它总是说它找不到记录。我正在尝试进行记忆交易,如果没有我的记录,我不能走得太远。非常感谢任何帮助 - 谢谢!

【问题讨论】:

    标签: erlang mnesia erl


    【解决方案1】:

    是的,使用 help() 并在 shell 中找到这些命令。

    rd(R,D)    -- define a record
    rf()       -- remove all record information
    rf(R)      -- remove record information about R
    rl()       -- display all record information
    rl(R)      -- display record information about R
    rp(Term)   -- display Term using the shell's record information
    rr(File)   -- read record information from File (wildcards allowed)
    rr(F,R)    -- read selected record information from file(s)
    rr(F,R,O)  -- read selected record information with options
    

    这些是 shell 中的一个巧妙的 hack,它们允许您在编译模块时加载模块中使用的记录定义。使用 rr 命令从您的模块中加载它。

    请记住,这些仅供交互式 shell 使用。

    【讨论】:

    • 补充一点:记录并不真正存在......它们只是标记的元组。例如。假设您定义了 -record(state, { sessions })。那么当你使用 #state{ session = N } 时,它实际上就是元组 {state, N}。同样,如果您只键入#state{},那么这将是 {state, undefined}。知道了这一点,您可以轻松地“伪造”记录,例如在 shell 中使用 mnesia 时。祝你好运。
    【解决方案2】:

    你是什么意思?在外壳中,就像克里斯蒂安所写的那样。如果您的意思是在模块中,那么您仍然必须先定义记录才能使用它们。有关如何执行此操作的说明,请参阅在线http://erlang.org/doc/ 的 erlang 文档。它们只是编译时构造,因此它们不存在。

    【讨论】:

      猜你喜欢
      • 2012-03-12
      • 2012-02-25
      • 2021-12-31
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 2013-01-06
      相关资源
      最近更新 更多