[erlang-questions] clarify: how to express this elegantly
Adam Lindberg
adam@REDACTED
Wed Dec 5 08:59:14 CET 2007
My take:
{Mod, Pid} = if
Value == "state";
Value == "rx_bit_rate";
Value == "tx_bit_rate";
Value == "ebno" ->
{circuit_monitor, CircuitMonitorPid};
Value == "packet_loss";
Value == "round_trip_time" ->
{node_pinger, NodePingerPid}
end,
?D,
Mod:plot_node_value(Pid, Socket, RequestId, CircuitId, FromDateTime,
ToDateTime, Width, Height, Value).
On Dec 4, 2007 10:23 PM, David Mercer <dmercer@REDACTED> wrote:
> 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
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071205/ee47b463/attachment.htm>
More information about the erlang-questions
mailing list