My take:<br><br><br>{Mod, Pid} = if<br> Value == "state";<br> Value == "rx_bit_rate";<br> Value == "tx_bit_rate";<br> Value == "ebno" -><br> {circuit_monitor, CircuitMonitorPid};
<br> Value == "packet_loss";<br> Value == "round_trip_time" -><br> {node_pinger, NodePingerPid}<br>end,<br>?D,<br>Mod:plot_node_value(Pid, Socket, RequestId, CircuitId, FromDateTime, ToDateTime, Width, Height, Value).
<br><br><br><div class="gmail_quote">On Dec 4, 2007 10:23 PM, David Mercer <<a href="mailto:dmercer@gmail.com">dmercer@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
How about:<br><br> Mod = (case Value of<br> "state" -> circuit_monitor;<br> "rx_bit_rate" -> circuit_monitor;<br> "tx_bit_rate" -> circuit_monitor;
<br> "ebno" -> circuit_monitor;<br> "packetloss" -> node_pinger;<br> "rtt" -> node_pinger<br> end),<br> Pid = (if Mod = circuit_monitor -> CircuitMonitorPid; true ->
<br>NodePingerPid),<br> Mod:plot_node_value(Pid, Socket,<br><div class="Ih2E3d"> RequestId, CircuitId, FromDateTime,<br>ToDateTime, Width, Height, Value<br> )<br>
<br></div>I'm not sure if that's any prettier, though...<br><br>DBM<br><div><div></div><div class="Wj3C7c"><br>-----Original Message-----<br>From: <a href="mailto:erlang-questions-bounces@erlang.org">erlang-questions-bounces@erlang.org
</a><br>[mailto:<a href="mailto:erlang-questions-bounces@erlang.org">erlang-questions-bounces@erlang.org</a>] On Behalf Of Matej Kosik<br>Sent: Tuesday, December 04, 2007 14:36<br>To: <a href="mailto:erlang-questions@erlang.org">
erlang-questions@erlang.org</a><br>Subject: [erlang-questions] clarify: how to express this elegantly<br><br>-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA1<br><br>Friends,<br><br>I wander, how can I express this:<br><br>
case Value of<br> "state" -><br> ?D,<br> circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,<br>
Height, Value<br> );<br> "rx_bit_rate" -><br> ?D,<br> circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,
<br>Height, Value<br> );<br> "tx_bit_rate" -><br> ?D,<br> circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,
<br>Height, Value<br> );<br> "ebno" -><br> ?D,<br> circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,
<br>Height, Value<br> );<br> "packetloss" -><br> ?D,<br> node_pinger:plot_node_value(NodePingerPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,
<br>Height, Value<br> );<br> "rtt" -><br> ?D,<br> node_pinger:plot_node_value(NodePingerPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,
<br>Height, Value<br> )<br> end<br><br>more elegantly. Via some kind of "variant patterns" such as:<br><br> case Value of<br> "state" | "rx_bit_rate" | "tx_bit_rate" | "ebno" ->
<br> ?D,<br> circuit_monitor:plot_node_value(CircuitMonitorPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,<br>Height, Value<br> );<br> "packet_loss" | "round_trip_time" ->
<br> ?D,<br> node_pinger:plot_node_value(NodePingerPid, Socket,<br> RequestId, CircuitId, FromDateTime, ToDateTime, Width,<br>Height, Value<br> )<br> end<br><br>but these do not exist :(
<br>These "variant patterns" could be introduced without any problems in special<br>cases when neither<br>variant contains unbound variable.<br>- --<br>Matej Kosik<br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG
v1.4.6 (GNU/Linux)<br>Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org" target="_blank">http://enigmail.mozdev.org</a><br><br>iD8DBQFHVbo7L+CaXfJI/hgRArySAJ47+Iin/aGeIBP04uNcJ/I5VlS2PwCePi27<br>QEDkkwClpMEL9WuA/3LICAo=
<br>=Y9ul<br>-----END PGP SIGNATURE-----<br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">
http://www.erlang.org/mailman/listinfo/erlang-questions</a><br><br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org
</a><br><a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></div></div></blockquote></div><br>