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

Matej Kosik <>
Tue Dec 4 21:36:11 CET 2007


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



More information about the erlang-questions mailing list