[erlang-questions] clarify: how to express this elegantly
Hynek Vychodil
vychodil.hynek@REDACTED
Wed Dec 5 10:20:36 CET 2007
Yet another implementation of same:
{Mod, Pid} = (
fun ("state") ->{circuit_monitor, CircuitMonitorPid};
("rx_bit_rate") ->{circuit_monitor, CircuitMonitorPid};
("tx_bit_rate") ->{circuit_monitor, CircuitMonitorPid};
("ebno") ->{circuit_monitor, CircuitMonitorPid};
("packet_loss") ->{node_pinger, NodePingerPid};
("round_trip_time") ->{node_pinger, NodePingerPid}
end)(Value),
?D,
Mod:plot_node_value(Pid, Socket, RequestId, CircuitId, FromDateTime,
ToDateTime, Width, Height, Value).
There are many implementations of this thing.
On 12/5/07, Adam Lindberg <adam@REDACTED> wrote:
> 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
> >
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
--
--Hynek (Pichi) Vychodil
More information about the erlang-questions
mailing list