这段代码有什么问题?我被期待"titi",person.name但我仍然有"toto"!更明确地说,如何修改函数中的记录?
init1()->
S=#person{name="toto"}, %record creation and field setting
fct(S),
io:format("~s~n",[S#person.name]).
fct(R)->
R#person{name="titi"}. %record updating
Run Code Online (Sandbox Code Playgroud)
hdi*_*ima 10
你需要得到fct()的结果:
init1()->
S=#person{name="toto"}, %record creation and field setting
S2 = fct(S), % Get updated record
io:format("~s~n",[S2#person.name]).
fct(R)->
R#person{name="titi"}. %record updating
Run Code Online (Sandbox Code Playgroud)
Bertaud,我认为你有点超越自己.在编写更多代码之前,您确实需要了解不可变性的基础知识.(即"变量"不会改变:你只能为它们分配一次值.)我建议你阅读免费的在线指南"了解你的好东西",请访问http://learnyousomeerlang.com/.涵盖变量基础知识的部分是http://learnyousomeerlang.com/starting-out-for-real#invariable-variables.