How to implement AND
guards in list comprehensions? Separating the guards with comma seems to word as OR
:
1> rd(r, {a, b}开发者_C百科).
r
2> L = [#r{a = 1, b =2}, #r{a = 1, b = 3}].
[#r{a = 1,b = 2},#r{a = 1, b = 3}]
3> [X || X <- L, X#r.a =/= 1, X#r.b =/= 2].
[]
Thanks a lot.
That's definitely an AND. The first element fails both tests; the second fails the X#r.a =/= 1
test.
If you want OR, simply use the orelse
operator:
2> [X || X <- L, X#r.a =/= 1 orelse X#r.b =/= 2].
[#r{a = 1,b = 3}]
精彩评论