1. 程式人生 > >elixir中的truth和true

elixir中的truth和true

bool nil per 使用 || boolean false ise 語言

在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

elixir中的truth和true