[Elixir] 시스템.
11186 단어 Elixir
소개
@im_miolab 씨, 감사합니다!
brew install elixir
에서 설치한 Elixir에서 IEx에서 Hello, world
만 한 경험뿐이었습니다만, 과감하게 LT를 한 추억이 있습니다 설치
mix new
$ mix new hello_env
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/hello_env.ex
* creating test
* creating test/test_helper.exs
* creating test/hello_env_test.exs
Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:
cd hello_env
mix test
Run "mix help" for more commands.
System.get_env/2에서 환경 변수를 읽고 Module attribute에 저장하는 모듈을 만듭니다.
lib/hello_env.exdefmodule HelloEnv do
@greet System.get_env("AWESOME_ENVIRONMENT_VARIABLE")
def greet do
@greet
end
end
환경 변수를 설정합니다.
defmodule HelloEnv do
@greet System.get_env("AWESOME_ENVIRONMENT_VARIABLE")
def greet do
@greet
end
end
.zshenv
export AWESOME_ENVIRONMENT_VARIABLE="I was born to love Elixir."
실행
$ source ~/.zshenv
$ cd hello_env
$ iex -S mix
Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Compiling 1 file (.ex)
Generated hello_env app
Interactive Elixir (1.10.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HelloEnv.greet
"I was born to love Elixir."
$ source ~/.zshenv
$ cd hello_env
$ iex -S mix
Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Compiling 1 file (.ex)
Generated hello_env app
Interactive Elixir (1.10.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HelloEnv.greet
"I was born to love Elixir."
AWESOME_ENVIRONMENT_VARIABLE을 변경하고 싶습니다.
iex(2)> System.halt
.zshenv
export AWESOME_ENVIRONMENT_VARIABLE="I was born to love Elixir. We are the Alchemists, my friends."
$ source ~/.zshenv
$ iex -S mix
Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Interactive Elixir (1.10.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HelloEnv.greet
"I was born to love Elixir."
해결법①
iex(2)> recompile force: true
Compiling 1 file (.ex)
Generated hello_env app
:ok
iex(3)> HelloEnv.greet
"I was born to love Elixir. We are the Alchemists, my friends.
해결법②
$ source ~/.zshenv
$ mix clean
$ iex -S mix
Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Compiling 1 file (.ex)
Generated hello_env app
Interactive Elixir (1.10.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HelloEnv.greet
"I was born to love Elixir. We are the Alchemists, my friends."
해결법③(다사이지만 언제나 내가 하고 있던 것)
lib/hello_env.ex
가 컴파일 오류를 일으키도록 이상한 작업을 수행하십시오 iex -S mix
Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Compiling 1 file (.ex)
== Compilation error in file lib/hello_env.ex ==
** (SyntaxError) lib/hello_env.ex:24: unexpected token: end
(elixir 1.10.4) lib/kernel/parallel_compiler.ex:304: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7
iex -S mix
Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Compiling 1 file (.ex)
Interactive Elixir (1.10.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HelloEnv.greet
"I was born to love Elixir. We are the Alchemists, my friends."
Wrapping Up
Reference
이 문제에 관하여([Elixir] 시스템.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/torifukukaiou/items/c2d13038280bd2431830텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)