如何在erlang中修改记录?

Yad*_*azo 8 erlang record immutability

我需要修改op记录中的值{place}和{other_place}.

#op{
    action   = [walk, from, {place}, to, {other_place}],
    preconds = [[at, {place}, me], [on, floor, me], 
                [other_place, {place}, {other_place}]],
    add_list = [[at, {other_place}, me]],
    del_list = [[at, {place}, me]]
}
Run Code Online (Sandbox Code Playgroud)

但是erlang不允许修改变量.是否有数据类型?

Jer*_*all 21

erlang不允许你修改变量是真的.但没有什么可以阻止你修改变量的副本.

鉴于你的记录:

Rec = #op{
    action   = [walk, from, {place}, to, {other_place}],
    preconds = [[at, {place}, me], [on, floor, me], 
                [other_place, {place}, {other_place}]],
    add_list = [[at, {other_place}, me]],
    del_list = [[at, {place}, me]]
}
Run Code Online (Sandbox Code Playgroud)

您可以有效地获得修改后的版本:

%% replaces the action field in Rec2 but everything else is the same as Rec.
Rec2 = Rec#op{action = [walk, from, {new_place}, to, {new_other_place}]}
Run Code Online (Sandbox Code Playgroud)

这将完成你似乎要问的事情.