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

Andras Georgy Bekes bekesa@REDACTED
Tue Dec 4 22:07:34 CET 2007


> 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
This can be written as (legal Erlang code):

if
   Value== "state" ; Value=="rx_bit_rate" ; Value=="tx_bit_rate" ; Value=="ebno" ->
      this;
   Value=="packet_loss" ; Value=="round_trip_time" ->
      that;
end

> These "variant patterns" could be introduced without any problems in
> special cases when neither variant contains unbound variable.
The interesting case is when the patterns do contain unbound variables.

	Georgy



More information about the erlang-questions mailing list