logo       

mapping implemented in functions vs in structures: msg#00362

lang.erlang.general

Subject: mapping implemented in functions vs in structures

I want to map entity x1 on machine m1 to y1 on m2 ...

I can see there are two choices and don't know which one
is the more idiomatic way in erlang world:

(1) functions
m1_m2(x1) -> y1;
m1_m2(x2) -> y2.
m3_m6(a1) -> b1;
m3_m6(a2) -> b2....

At run time,
suppose A = m1, B = m2, X = x1.
To get y1,
I will need to form a string S ="m1_m2(x1)"
and evaluate it.
btw, how do I do this ? erl_eval:expr() looks complicated.

(2) structures
{{m1_m2, [{x1, y1},
{x2, y2}]},
{m3_m6, [{a1, b1},
{a2, b2}]}

Given A, B, X in (1), finding y1 becomes
a matter of parsing the structure.

thanks,
HP




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise