学习:record用法

详情请参考官网:http://www.erlang.org/doc/reference_manual/records.html

http://www.erlang.org/doc/programming_examples/records.html

1. record本质上是tuple.

2.获取record的结构相关的信息的函数:

To each module using records, a pseudo function is added during compilation to obtain information about records:

record_info(fields, Record) -> [Field]
record_info(size, Record) -> Size

Size is the size of the tuple representation, that is one more than the number of fields.

In addition, #Record.Name returns the index in the tuple representation of Name of the record Record. Name must be an atom.

 

1> rd(state,{age,sex}).
state
2> State = #state{age = 27,sex = 1}.
#state{age = 27,sex = 1}
3> State.
#state{age = 27,sex = 1}
4> io:format("~w~n",[State]).
{state,27,1}
ok
5> tuple_to_list(State).
[state,27,1]
6> NewState = State#state{age=28}.
#state{age = 28,sex = 1}
7> State#state.age.
27


9> record_info(fields,state).
[age,sex]
10> record_info(size,state).
3

rd():在控制台中定义record.

 

原文地址:https://www.cnblogs.com/ribavnu/p/3714131.html