[erlang-questions] clarify: how to express this elegantly
David Mercer
dmercer@REDACTED
Tue Dec 4 22:23:40 CET 2007
How about:
Mod = (case Value of
"state" -> circuit_monitor;
"rx_bit_rate" -> circuit_monitor;
"tx_bit_rate" -> circuit_monitor;
"ebno" -> circuit_monitor;
"packetloss" -> node_pinger;
"rtt" -> node_pinger
end),
Pid = (if Mod = circuit_monitor -> CircuitMonitorPid; true ->
NodePingerPid),
Mod:plot_node_value(Pid, Socket,
RequestId, CircuitId, FromDateTime,
ToDateTime, Width, Height, Value
)
I'm not sure if that's any prettier, though...
DBM
-----Original Message-----
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Matej Kosik
Sent: Tuesday, December 04, 2007 14:36
To: erlang-questions@REDACTED
Subject: [erlang-questions] clarify: how to express this elegantly
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Friends,
I wander, how can I express this:
case Value of
"state" ->
?D,
circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
);
"rx_bit_rate" ->
?D,
circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
);
"tx_bit_rate" ->
?D,
circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
);
"ebno" ->
?D,
circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
);
"packetloss" ->
?D,
node_pinger:plot_node_value(NodePingerPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
);
"rtt" ->
?D,
node_pinger:plot_node_value(NodePingerPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
)
end
more elegantly. Via some kind of "variant patterns" such as:
case Value of
"state" | "rx_bit_rate" | "tx_bit_rate" | "ebno" ->
?D,
circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
);
"packet_loss" | "round_trip_time" ->
?D,
node_pinger:plot_node_value(NodePingerPid, Socket,
RequestId, CircuitId, FromDateTime, ToDateTime, Width,
Height, Value
)
end
but these do not exist :(
These "variant patterns" could be introduced without any problems in special
cases when neither
variant contains unbound variable.
- --
Matej Kosik
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHVbo7L+CaXfJI/hgRArySAJ47+Iin/aGeIBP04uNcJ/I5VlS2PwCePi27
QEDkkwClpMEL9WuA/3LICAo=
=Y9ul
-----END PGP SIGNATURE-----
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list