No subject

Papa Tana papa.tana101@REDACTED
Fri Jul 31 22:21:34 CEST 2020


Your codes, guys, are both working and are very straightforward.

Maybe I need to make a break... Sorry All, I even forgot to put the
email subject.

Thanks


2020-07-31 22:36 UTC+03:00, Leonard B <leonard.boyce@REDACTED>:
> You could just head match of that specification is reliable and has not
> variance
>
> msg_type([{outnum, _}]) -> 1; %% only has outnum
> msg_type(_) -> 2. %% may have other values
>
> or if unreliable:
>
> msg_type([{outnum, _}]) -> 1; %% only has outnum
> msg_type(L) ->
>   %% Only contains innum and outnum, badmatch crash if not
>   [innum, outnum] = lists:usort([element(1,Kv) || Kv <- L]),
>   2.
>
> ```
> 1> MT = fun MT([{outnum, _}]) -> 1; MT(L) -> [innum, outnum] =
> lists:usort([element(1,KV) || KV <- L]), 2 end.
> #Fun<erl_eval.30.50752066>
> 2> Spec1 = [{outnum,"configure"}].
> [{outnum,"configure"}]
> 3> Spec2 = [{outnum,"configure"},{innum,
> challenge,"Rand","Kc"},{innum, response ,"Rand","Sres"}].
> [{outnum,"configure"},
> {innum,challenge,"Rand","Kc"},
> {innum,response,"Rand","Sres"}]
> 4> MT(Spec1).
> 1
> 5> MT(Spec2).
> 2
> 6> MT([{other,sdsf} | Spec2]).
> ** exception error: no match of right hand side value [innum,other,outnum]
> 7>
> ```
>
>
> Kind regards,
> Leonard
>
>
> On Fri, Jul 31, 2020 at 3:11 PM Papa Tana <papa.tana101@REDACTED> wrote:
>>
>> Hi,
>>
>> I receive Msg from some device in the network, and Msg exist only in 2
>> versions, like below :
>>
>> Version1:
>> -------------
>> Msg = [{outnum,"configure"}].
>>
>> OR
>>
>> Version2:
>> -------------
>> Msg =
>> [{outnum,"configure"},
>>  {innum, challenge,"Rand","Kc"},
>>  {innum, response ,"Rand","Sres"}].
>>
>> I tried to make a list comprehension but the structure of each item is
>> different depending it's a outnum(2) or an innum(4).
>>
>> I need to process the Msg list, so that:
>>
>>  - if Msg is type Version 1, ie contains outnum ONLY, do action for
>> outnum;
>>  - if Msg contains BOTH innum + outnum (Version2), do action inoutnum;
>>
>> Can anyone advice please?
>>
>> Thanks,
>


More information about the erlang-questions mailing list