How do I modify a record in erlang?

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?

Answers


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.


Need Your Help

Oracle XE Database Configuration failed

database oracle11g vps oracle-xe

I am trying to create an oracle xe database in my vps.

What is "reliable write" in BLE?

android bluetooth-lowenergy android-bluetooth

In Android's BLE API (BluetoothGatt) there are methods that deal with reliable writes: