elixir中的truth和true

在elixir中, true 就是true 或者是:true 是一个原子 atom, 

在其他语言中的true,这里叫做truth, 只要你不是false,nil ,就是truth, 当然 false和nil也是原子

 

所以说elixir中Boolean operators 是针对true

 

  

a or b # true if a is true, otherwise b
a and b # false if a is false, otherwise b
not a  # false if a is true, true otherwise

Relaxed Boolean operators 是针对truth使用

a || b # a if a is truthy, otherwise b
a && b # a if a is truthy, otherwise b
!a # a if a is truthy, otherwise b

posted on 2017-07-26 23:51  c3tc3tc3t  阅读(838)  评论(0编辑  收藏  举报