如何修改erlang中的记录? [英] How do I modify a record in erlang?
本文介绍了如何修改erlang中的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#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]]
}
但是,erlang不允许修改变量。有没有数据类型?
解决方案
erlang不允许你修改变量是真的。但是没有什么可以阻止你修改变量的副本。
给定你的记录:
code> 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 = [[在{place},我]]
}
您可以有效获取修改版本如下所示:
%%替换Rec2中的操作字段,但其他所有内容与Rec相同。
Rec2 = Rec#op {action = [walk,from,{new_place},to,{new_other_place}}}
这将完成你似乎在问的问题。
I to need modify the values {place} and {other_place} in the op record.
#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]]
}
But erlang don´t allow modifying variables. Is there a data type for that?
解决方案
erlang doesn't let you modify variables it is true. But nothing prevents you from making modified copies of a variable.
Given your record:
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]]
}
You can effectively get a modified version like so:
%% 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}]}
This will accomplish what you seem to be asking.
这篇关于如何修改erlang中的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文