学习:record用法

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

详情请参考官网: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.

 

相关文章
|
8月前
|
存储 数据挖掘 数据库
data的含义与作用及使用方法
data的含义与作用及使用方法
6070 0
|
9月前
|
存储 C++ 容器
C++中set的用法学习
Set是C++ STL(标准模板库)的一个容器类,它用于存储不同的值,并且可以按照特定顺序进行访问和操作。Set是一种基于红黑树实现的关联容器,也就是说它的元素按照固定的顺序排列,且每个元素都唯一。 Set中包含的元素是自动排序的,因此,如果你需要在存储值的同时能够高效的进行查找,那么Set会是一个很好的选择。
189 0
开发指南—Sequence—显示用法—修改Sequence
本文主要介绍如何对Sequence的各种类型进行修改。
115 0
|
索引
开发指南—Sequence—隐式用法—CREATE TABLE
在为拆分表或广播表的主键定义AUTO_INCREMENT后,Sequence可以用于自动填充主键,由PolarDB-X自动维护。 扩展标准建表语法,增加了自增列的Sequence类型,如果未指定类型关键字,则默认类型为GROUP。PolarDB-X自动创建的、跟表相关联的Sequence名称,都是以AUTO_SEQ_为前缀,后面加上表名。
|
数据库
dataguard 搭建
dataguard 搭建
113 0
|
Java 物联网 Python
物联网发展的三大编程语言
虽然Java是物联网开发中使用最多的语言,但是Java和Python在物联网开发的不同子域中紧随其后。物联网发展的未来可能仍然是多语言的。十年前,可能没有人想象未来有一天我们使用的空调、冰箱可以智能可控,路上行驶的汽车可以自动驾驶,现在,这些都将变得现实,而让这些变得现实的就是物联网。
20434 1
|
C++ 编译器
读书笔记 effective c++ Item 16 成对使用new和delete时要用相同的形式
1. 一个错误释放内存的例子 下面的场景会有什么错? 1 std::string *stringArray = new std::string[100]; 2 3 ... 4 5 delete stringArray   一切看上去都是有序的。
710 0