Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang list comprehension

I'm testing an expression with two inequalities for the condition of a list comprehension. Is there a way to have assignments here and not duplicate that expression?

The following code doesn't work, but I wish it would:

diagnose(Expertise,PatientSymptoms) ->
    {[CertainDisease||
         {CertainDisease,KnownSymptoms}<-Expertise,
         C=length(PatientSymptoms)-length(PatientSymptoms--KnownSymptoms),
         C>=2,
         C<=5      
      ]}.
like image 292
titus Avatar asked Dec 01 '22 03:12

titus


1 Answers

A way of writing it directly without a fun would be to use a begin ... end block ending with a boolean test:

[ CertainDisease || {CertainDisease,KnownSymptoms} <- Expertise,
                    begin
                        C = length(PatientSymptoms) - length(PatientSymptoms -- KnownSymptoms),
                        C >= 2 andalso C <= 5
                    end ]
like image 99
rvirding Avatar answered Feb 15 '23 22:02

rvirding