views:

203

answers:

1

Hi, I need replace the same value for variables {place} and {other_place} in the record op.

#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 share variables. Is there any data type for that?

+5  A: 

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.

Jeremy Wall
Excelent. Thank you!
Yadira Suazo
your welcome glad to help.
Jeremy Wall