2010-04-26 84 views
6

我需要修改操作记录中的值{place}和{other_place}。如何修改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不允许修改变量。有没有数据类型?

+1

请用4格缩进来格式化您的代码。 (或者选择它们并按Ctrl + K。) – 2010-04-26 17:35:16

+0

问题是什么,dawg? – 2010-04-26 17:36:11

+6

您可以像解决其他问题一样解决Erlang中的NP完全问题,它只需要更长的时间。请至少重新回答你的问题。 – 2010-04-26 17:43:32

回答

19

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]] 
} 

可以有效地得到修改后的版本,像这样:

%% 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}]} 

这将完成你仿佛在问。

+0

优秀。谢谢!欢迎您致电 – 2010-04-26 23:55:37

+0

。 – 2010-04-27 00:32:21

+0

呃,让我搞砸了我的脸。我放弃了Erlang – Acidic 2018-01-26 15:32:20