In addition to the Elixir file extension .ex, Elixir also supports .exs files for scripting. Elixir treats both files exactly the same way, the only difference is in intention. .ex files are meant to be compiled while .exs files are used for scripting. When executed, both extensions compile and load their modules into memory, although only .ex files write their bytecode to disk in the format of .beam files.
Elixir 對於不管是 ex 或者是 exs 檔案,都會將他們編譯後執行;只是在 ex 檔案,Elixir 會將他們寫成 beam格式的二元組碼到硬碟。
至於要怎麼將 hello world 當一個模組來引用呢?首先我們必須先建立一個模組,在 Elixir 我們需要用 mix 來建立一個專案模組。
那我們就在終端機裡面輸入 mix new hello_world 這裡的 hello_world 是我們的專案模組名稱,
所以如果你專案名稱叫 hello_elixir 的話就要輸入 mix new hello_elixir。題外話,在 mix 他預設適用 snake case 的命名方式,所以如果用 - 連接的話,或者是用 camcel case,就會發生如下畫面:
$ mix new hello-world
** (Mix) Application name must start with a lowercase ASCII letter, followed by lowercase ASCII letters, numbers, or underscores, got: "hello-world". The application name is inferred from the path, if you'd like to explicitly name the application then use the "--app APP" option
$ mix new helloWorld
** (Mix) Application name must start with a lowercase ASCII letter, followed by lowercase ASCII letters, numbers, or underscores, got: "helloWorld". The application name is inferred from the path, if you'd like to explicitly name the application then use the "--app APP" option