global.person_data = class public gender = "M" in {"F", "M"}; public age = 1 in 1 : 150; public first = "Mark" in ~/[A-Za-z][A-Za-z]*/; public last = "Brown" in ~/[A-Za-z][A-Za-z]*/; new = (gender, age, first, last) -> (); end global.person_ref = class private data_p; auto gender = () -> (parent.data_p) >>. gender; auto age = () -> (parent.data_p) >>. age auto first = () -> (parent.data_p) >>. first auto last = () -> (parent.data_p) >>. last new = function (gender, age, first, last) -> () data_p = newpointer(global.person_data.new(gender, age, first, last)); end common set_gender = function x -> () (parent.data_p) >>. gender = x; end common set_age = function x -> () (parent.data_p) >>. age = x; end common set_first = function x -> () (parent.data_p) >>. first = x; end common set_last = function x -> () (parent.data_p) >>. last = x; end end p1 = person_ref.new("M",25,"Derek", "Burke"); p1.set_age(29);Now p1 acts as a reference to the actual person data. Copies of p1 are like aliases of the same person. If a copy of p1 is updated, the original p1 will undergo the same change.
p2 = p1; p2.set_age(35); p2.age // ans is 35 p1.age // ans is 35 also