2010-04-26 83 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