Erlang列表理解 [英] Erlang list comprehension
本文介绍了Erlang列表理解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在测试一个表达式,其中两个不等式用于列表推导的条件。有没有办法在这里做任务,而不是重复那个表达?
(以下代码不起作用,但我希望这样)
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
]}.
推荐答案
直接写一个 fun
将使用以布尔测试结尾的 begin ... end
块: / p>
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 ]
这篇关于Erlang列表理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文