mapping implemented in functions vs in structures
Vladimir Sekissov
svg@REDACTED
Fri Apr 25 00:33:07 CEST 2003
Good day,
But why not:
map_el(m1, m2, x1) -> y1;
map_el(m1, m2, x2) -> y2;
...
or
map_el({m1, m2}, x1) -> y1;
map_el({m1, m2}, x2) -> y2;
...
Best Regards,
Vladimir Sekissov
hp> I want to map entity x1 on machine m1 to y1 on m2 ...
hp>
hp> I can see there are two choices and don't know which one
hp> is the more idiomatic way in erlang world:
hp>
hp> (1) functions
hp> m1_m2(x1) -> y1;
hp> m1_m2(x2) -> y2.
hp> m3_m6(a1) -> b1;
hp> m3_m6(a2) -> b2....
hp>
hp> At run time,
hp> suppose A = m1, B = m2, X = x1.
hp> To get y1,
hp> I will need to form a string S ="m1_m2(x1)"
hp> and evaluate it.
hp> btw, how do I do this ? erl_eval:expr() looks complicated.
hp>
hp> (2) structures
hp> {{m1_m2, [{x1, y1},
hp> {x2, y2}]},
hp> {m3_m6, [{a1, b1},
hp> {a2, b2}]}
hp>
hp> Given A, B, X in (1), finding y1 becomes
hp> a matter of parsing the structure.
hp>
hp> thanks,
hp> HP
More information about the erlang-questions
mailing list