定义一个record文件 1.erl:
-record(todo, {status=reminder, who=joe, text}).
定义并操纵记录:
1> rr("1.erl").
[todo]
2> X=#todo{}.
#todo{status = reminder,who = joe,text = undefined}
3> X1=#todo{status=urgent, text="Fix errata in book"}.
#todo{status = urgent,who = joe,text = "Fix errata in book"}
4> X2 = X1#todo{status=done}. %创建一个X1的副本,并将status字段设为done
#todo{status = done,who = joe,text = "Fix errata in book"}
从记录中提取字符串:
5> #todo{who=W, text=Txt} = X2.
#todo{status = done,who = joe,text = "Fix errata in book"}
6> W.
joe
7> Txt.
"Fix errata in book"
如果想提取某个字段的值,也可以
9> X2#todo.text.
"Fix errata in book"
阅读(1997) | 评论(0) | 转发(0) |