Guest User

Untitled

a guest
Dec 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. defmodule Sample do
  2. # 1. アットリビュート(モジュール内でのみ参照可能)
  3. @private_const_value 1
  4. # 2. 関数を定数のように扱う(これは可能)
  5. def const_value_func, do: 3
  6. # 3. 定義イメージ(コンパイルエラー)
  7. PUBLIC_CONST_VALUE = 2
  8. end
  9.  
  10. defmodule Client do
  11. def foo() do
  12. # 1. アットリビュートは他モジュールでは参照不可
  13. IO.puts "CONST = #{Sample.@private_const_value}"
  14. # 2. 関数を定数として使う
  15. IO.puts "CONST = #{Sample.const_value_func}"
  16. # 3. 他モジュールで定義した定数を参照
  17. IO.puts "CONST = #{Sample.PUBLIC_CONST_VALUE}"
  18. end
  19. end
Add Comment
Please, Sign In to add comment