[erlang-questions] clarify: how to express this elegantly

Jani Launonen launoja@REDACTED
Tue Dec 4 22:16:10 CET 2007


I don't know if it is a real improvement, but how about using if?

if
	Value = "state" ;
	Value = "rx_bit_rate" ;
	Value = "tx_bit_rate" ;
	Value = "ebno" ->
		?D,
		circuit_monitor:plot_node_value(CircuitMonitorPid, Socket, RequestId,
					 CircuitId, FromDateTime, ToDateTime, Width, Height, Value);

	Value = "packetloss" ;
	Value = "rtt" ->
		?D,
		node_pinger:plot_node_value(NodePingerPid, Socket,
		RequestId, CircuitId, FromDateTime, ToDateTime, Width, Height, Value)
end


Jani.
	


Matej Kosik kirjoitti 4.12.2007 kello 22.36:

>
> -----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