├── 1st-edition ├── appB │ └── ex1-docs │ │ ├── combined │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── docs │ │ │ ├── Combined.html │ │ │ ├── Convert.html │ │ │ ├── Drop.html │ │ │ ├── css │ │ │ │ ├── full_list.css │ │ │ │ └── style.css │ │ │ ├── exceptions_list.html │ │ │ ├── index.html │ │ │ ├── js │ │ │ │ ├── app.js │ │ │ │ ├── full_list.js │ │ │ │ └── jquery.js │ │ │ ├── modules_list.html │ │ │ ├── overview.html │ │ │ ├── protocols_list.html │ │ │ └── records_list.html │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ ├── mix.lock │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ │ └── docs │ │ ├── css │ │ ├── full_list.css │ │ └── style.css │ │ ├── index.html │ │ ├── js │ │ ├── app.js │ │ ├── full_list.js │ │ └── jquery.js │ │ ├── modules_list.html │ │ ├── protocols_list.html │ │ └── records_list.html ├── ch02 │ ├── ex1-drop │ │ └── drop.ex │ ├── ex2-split │ │ ├── convert.ex │ │ └── drop.ex │ ├── ex3-combined │ │ ├── combined.ex │ │ ├── convert.ex │ │ └── drop.ex │ ├── ex4-pipe │ │ ├── combined.ex │ │ ├── convert.ex │ │ └── drop.ex │ ├── ex5-import │ │ ├── combined.ex │ │ ├── convert.ex │ │ └── drop.ex │ ├── ex6-defaults │ │ └── drop.ex │ └── ex7-docs │ │ ├── combined.ex │ │ ├── convert.ex │ │ └── drop.ex ├── ch03 │ ├── ex1-atoms │ │ └── drop.ex │ ├── ex2-guards │ │ ├── drop.ex │ │ └── mathDemo.ex │ ├── ex3-underscore │ │ ├── drop.ex │ │ └── drop2.ex │ ├── ex4-tuples │ │ └── drop.ex │ └── ex5-tuplesMore │ │ ├── drop.ex │ │ ├── drop2.ex │ │ └── drop3.ex ├── ch04 │ ├── ex1-case │ │ └── drop.ex │ ├── ex10-factorial-down-instrumented │ │ └── fact.ex │ ├── ex11-factorial-up │ │ └── fact.ex │ ├── ex2-case │ │ └── drop.ex │ ├── ex3-case │ │ └── drop.ex │ ├── ex4-cond │ │ └── drop.ex │ ├── ex5-if │ │ └── drop.ex │ ├── ex6-broken │ │ └── broken.ex │ ├── ex7-countdown │ │ └── count.ex │ ├── ex8-countup │ │ └── count.ex │ └── ex9-factorial-down │ │ └── fact.ex ├── ch05 │ ├── ex1-ask │ │ └── ask.ex │ └── ex2-ask │ │ ├── ask.ex │ │ └── drop.ex ├── ch06 │ ├── ex1-product │ │ └── overall.ex │ ├── ex2-drop │ │ ├── drop.ex │ │ └── listdrop.ex │ ├── ex3-drop │ │ ├── drop.ex │ │ └── listdrop.ex │ └── ex4-pascal │ │ └── pascal.ex ├── ch07 │ ├── ex1-struct │ │ ├── planemo.ex │ │ └── tower.ex │ ├── ex2-struct-match │ │ ├── struct_drop.ex │ │ └── structs.ex │ ├── ex3-struct-components │ │ ├── struct_drop.ex │ │ └── structs.ex │ ├── ex4-struct-multi │ │ ├── struct_drop.ex │ │ └── structs.ex │ ├── ex5-protocol │ │ ├── planemo.ex │ │ ├── tower.ex │ │ └── valid_protocol.ex │ ├── ex6-protocol │ │ ├── planemo.ex │ │ ├── tower.ex │ │ └── valid_protocol.ex │ └── ex7-inspect │ │ ├── planemo.ex │ │ ├── tower.ex │ │ └── valid_protocol.ex ├── ch08 │ └── ex1-hof │ │ └── hof.ex ├── ch09 │ ├── ex1-simple │ │ └── bounce.ex │ ├── ex10-resilient │ │ ├── drop.ex │ │ └── mph_drop.ex │ ├── ex2-recursion │ │ └── bounce.ex │ ├── ex3-counter │ │ ├── bounce.ex │ │ └── ttb_last_config │ ├── ex3-debug │ │ └── fact.ex │ ├── ex4-state │ │ └── bounce.ex │ ├── ex4-testing │ │ ├── drop.ex │ │ ├── drop_bad.ex │ │ ├── drop_test.exs │ │ ├── drop_test2.exs │ │ ├── drop_test3.exs │ │ └── drop_test4.exs │ ├── ex5-division │ │ └── bounce.ex │ ├── ex6-talking │ │ └── drop.ex │ ├── ex7-talkingProcs │ │ ├── drop.ex │ │ └── mph_drop.ex │ ├── ex8-linking │ │ ├── drop.ex │ │ └── mph_drop.ex │ └── ex9-trapping │ │ ├── drop.ex │ │ └── mph_drop.ex ├── ch10 │ ├── ex1-tryCatch │ │ ├── drop.ex │ │ ├── drop2.ex │ │ └── drop3.ex │ ├── ex2-debug │ │ ├── drop.ex │ │ └── mph_drop.ex │ ├── ex3-debug │ │ └── fact.ex │ └── ex4-testing │ │ ├── drop.ex │ │ ├── drop_bad.ex │ │ ├── drop_test.exs │ │ ├── drop_test2.exs │ │ ├── drop_test3.exs │ │ └── drop_test4.exs ├── ch11 │ ├── ex1-records │ │ ├── records.ex │ │ └── user.ex │ ├── ex2-records │ │ ├── record_drop.ex │ │ └── records.ex │ ├── ex3-records │ │ ├── record_drop.ex │ │ └── records.ex │ ├── ex4-records │ │ ├── record_drop.ex │ │ └── records.ex │ ├── ex5-ets │ │ ├── planemo_storage.ex │ │ └── records.ex │ ├── ex6-ets │ │ ├── planemo_storage.ex │ │ └── records.ex │ ├── ex7-ets-calculator │ │ ├── drop.ex │ │ ├── mph_drop.ex │ │ └── records.ex │ ├── ex8-mnesia │ │ ├── drop.ex │ │ ├── mph_drop.ex │ │ └── records.ex │ └── ex9-qlc │ │ ├── records.ex │ │ └── test.ex ├── ch12 │ ├── ex1-drop │ │ ├── drop-server2.ex │ │ ├── drop_server.ex │ │ └── testor.ex │ ├── ex2-drop-sup │ │ ├── drop_server.ex │ │ └── drop_sup.ex │ ├── ex3-drop-app │ │ └── drop_app │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── config │ │ │ └── config.exs │ │ │ ├── lib │ │ │ ├── drop_app.ex │ │ │ ├── drop_server.ex │ │ │ └── drop_sup.ex │ │ │ ├── mix.exs │ │ │ └── test │ │ │ ├── drop_app_test.exs │ │ │ └── test_helper.exs │ └── ex3-drop-app2 │ │ └── drop_app │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ ├── drop_app.ex │ │ ├── drop_server.ex │ │ └── drop_sup.ex │ │ ├── mix.exs │ │ └── test │ │ ├── drop_app_test.exs │ │ └── test_helper.exs └── ch13 │ ├── ex1-difference │ └── difference.ex │ ├── ex2-double │ └── double.ex │ ├── ex3-double │ └── double.ex │ ├── ex4-unless │ └── logic.ex │ ├── ex5-programmatic │ ├── function_maker.ex │ └── multiply.ex │ └── ex6-multidrop │ ├── drop.ex │ └── function_maker.ex ├── 2nd-edition ├── build_output.txt ├── builder.pl ├── ch02 │ ├── ex1-drop │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex10-doc-specs │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ ├── ex11-doc-module │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ ├── ex2-split │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex3-combined │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ ├── ex4-combined │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ ├── ex4a-pipe │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ ├── ex5-import-erlang │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex5-import │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ ├── ex6-defaults │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex7-docs │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── combined.ex │ │ │ ├── convert.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── combined_test.exs │ │ │ └── test_helper.exs │ └── ex8-doc-function │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ ├── combined.ex │ │ ├── convert.ex │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ ├── combined_test.exs │ │ └── test_helper.exs ├── ch03 │ ├── absolute-value-1 │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── math_demo.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── math_demo_test.exs │ │ │ └── test_helper.exs │ ├── absolute-value-2 │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── math_demo.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── math_demo_test.exs │ │ │ └── test_helper.exs │ ├── ex1-atoms │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex2-guards │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex3-underscore │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── drop2.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex4-tuples │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ └── ex5-tuplesMore │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ ├── drop_test.exs │ │ └── test_helper.exs ├── ch04 │ ├── ex1-case │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ ├── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ │ └── xbuild │ │ │ └── dev │ │ │ ├── consolidated │ │ │ └── .compile.protocols │ │ │ └── lib │ │ │ └── drop │ │ │ ├── .compile.elixir │ │ │ ├── .compile.elixir_scm │ │ │ ├── .compile.xref │ │ │ └── ebin │ │ │ └── drop.app │ ├── ex10-factorial-down-instrumented │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── fact.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── fact_test.exs │ │ │ └── test_helper.exs │ ├── ex11-factorial-down-tail-recursive │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── fact.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── fact_test.exs │ │ │ └── test_helper.exs │ ├── ex11-factorial-up │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── fact.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── fact_test.exs │ │ │ └── test_helper.exs │ ├── ex2-case │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex3-case │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex4-cond │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex5-if │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex6-broken │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── broken.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── broken_test.exs │ │ │ └── test_helper.exs │ ├── ex7-countdown │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── count.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── count_test.exs │ │ │ └── test_helper.exs │ ├── ex8-countup │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── count.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── count_test.exs │ │ │ └── test_helper.exs │ └── ex9-factorial-down │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ └── fact.ex │ │ ├── mix.exs │ │ └── test │ │ ├── fact_test.exs │ │ └── test_helper.exs ├── ch05 │ ├── ex1-ask │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── ask.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── ask_test.exs │ │ │ └── test_helper.exs │ ├── ex2-ask │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── ask.ex │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── ask_test.exs │ │ │ └── test_helper.exs │ └── ex3-ask │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ ├── ask.ex │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ ├── ask_test.exs │ │ └── test_helper.exs ├── ch06 │ ├── ex1-product │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── overall.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── overall_test.exs │ │ │ └── test_helper.exs │ ├── ex2-drop │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── list_drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── list_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex3-drop │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── list_drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── list_drop_test.exs │ │ │ └── test_helper.exs │ └── ex4-pascal │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ └── pascal.ex │ │ ├── mix.exs │ │ └── test │ │ ├── pascal_test.exs │ │ └── test_helper.exs ├── ch07 │ ├── ex1-struct │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo.ex │ │ │ └── tower.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── test_helper.exs │ │ │ └── tower_test.exs │ ├── ex2-struct-match │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo.ex │ │ │ ├── struct_drop.ex │ │ │ └── tower.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── struct_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex3-struct-components │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo.ex │ │ │ ├── struct_drop.ex │ │ │ └── tower.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── struct_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex4-struct-multi │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo.ex │ │ │ ├── struct_drop.ex │ │ │ └── tower.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── struct_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex5-protocol │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo.ex │ │ │ ├── tower.ex │ │ │ └── valid.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── test_helper.exs │ │ │ └── valid_test.exs │ ├── ex6-protocol │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo.ex │ │ │ ├── tower.ex │ │ │ └── valid.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── test_helper.exs │ │ │ └── valid_test.exs │ └── ex7-inspect │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ ├── planemo.ex │ │ ├── tower.ex │ │ └── valid.ex │ │ ├── mix.exs │ │ └── test │ │ ├── test_helper.exs │ │ └── valid_test.exs ├── ch08 │ └── ex1-hof │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ └── hof.ex │ │ ├── mix.exs │ │ └── test │ │ ├── hof_test.exs │ │ └── test_helper.exs ├── ch09 │ ├── ex1-simple │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── bounce.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── bounce_test.exs │ │ │ └── test_helper.exs │ ├── ex10-resilient │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── mph_drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── mph_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex2-recursion │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── bounce.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── bounce_test.exs │ │ │ └── test_helper.exs │ ├── ex3-counter │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── bounce.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── bounce_test.exs │ │ │ └── test_helper.exs │ ├── ex4-state │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── bounce.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── bounce_test.exs │ │ │ └── test_helper.exs │ ├── ex5-division │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── bounce.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── bounce_test.exs │ │ │ └── test_helper.exs │ ├── ex6-talking │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex7-talkingProcs │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── mph_drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── mph_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex8-linking │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── mph_drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── mph_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex9-trapping │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── mph_drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── mph_drop_test.exs │ │ │ └── test_helper.exs │ └── testor │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ ├── drop.ex │ │ └── mph_drop.ex │ │ ├── mix.exs │ │ └── test │ │ ├── mph_drop_test.exs │ │ └── test_helper.exs ├── ch10 │ ├── ex1-tryCatch │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex1a-tryCatch │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex1b-tryCatch │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex2-debug │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ └── mph_drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── mph_drop_test.exs │ │ │ └── test_helper.exs │ └── ex3-debug │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ └── fact.ex │ │ ├── mix.exs │ │ └── test │ │ ├── fact_test.exs │ │ └── test_helper.exs ├── ch11 │ ├── dia_test │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── dia_test.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── dia_test_test.exs │ │ │ └── test_helper.exs │ ├── ex1-guards │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex2-specs │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── specs.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── specs_test.exs │ │ │ └── test_helper.exs │ ├── ex3-specs │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── new_type.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── new_type_test.exs │ │ │ └── test_helper.exs │ ├── ex4-testing │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop_bad.ex │ │ │ └── drop_good.ee │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex4a-testing │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop2_test.exs │ │ │ ├── drop3_test.exs │ │ │ ├── drop4_test.exs │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex5-setup │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ ├── ex6-doctest │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_test.exs │ │ │ └── test_helper.exs │ └── zorko │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ └── zorko.ex │ │ ├── mix.exs │ │ └── test │ │ ├── test_helper.exs │ │ └── zorko_test.exs ├── ch12 │ ├── ex1-records │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── records_test.exs │ │ │ └── test_helper.exs │ ├── ex2-records │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── record_drop.ex │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── record_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex3-records │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── record_drop.ex │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── record_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex4-records │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── record_drop.ex │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── record_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex5-ets │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo_storage.ex │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── planemo_storage_test.exs │ │ │ └── test_helper.exs │ ├── ex6-ets │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── planemo_storage.ex │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── planemo_storage_test.exs │ │ │ └── test_helper.exs │ ├── ex7-ets-calculator │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ ├── mph_drop.ex │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── mph_drop_test.exs │ │ │ └── test_helper.exs │ ├── ex8-mnesia │ │ ├── .gitignore │ │ ├── Mnesia.nonode@nohost │ │ │ ├── DECISION_TAB.LOG │ │ │ ├── LATEST.LOG │ │ │ └── schema.DAT │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop.ex │ │ │ ├── mph_drop.ex │ │ │ └── records.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── mph_drop_test.exs │ │ │ └── test_helper.exs │ └── tower_definitions.txt ├── ch13 │ ├── ex1-drop │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── drop_server.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_server_test.exs │ │ │ └── test_helper.exs │ ├── ex2-drop-sup │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── drop_server.ex │ │ │ └── drop_sup.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── drop_sup_test.exs │ │ │ └── test_helper.exs │ └── ex3-drop-app │ │ └── drop_app │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ ├── drop_app.ex │ │ ├── drop_server.ex │ │ └── drop_sup.ex │ │ ├── mix.exs │ │ └── test │ │ ├── drop_app_test.exs │ │ └── test_helper.exs ├── ch14 │ ├── ex1-difference │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── difference.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── difference_test.exs │ │ │ └── test_helper.exs │ ├── ex2-double │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── bad_double.ex │ │ │ └── double.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── double_test.exs │ │ │ └── test_helper.exs │ ├── ex3-double │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── double.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── double_test.exs │ │ │ └── test_helper.exs │ ├── ex4-unless │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ └── logic.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── logic_test.exs │ │ │ └── test_helper.exs │ ├── ex5-programmatic │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ │ └── config.exs │ │ ├── lib │ │ │ ├── function_maker.ex │ │ │ └── multiply.ex │ │ ├── mix.exs │ │ └── test │ │ │ ├── multiply_test.exs │ │ │ └── test_helper.exs │ └── ex6-multidrop │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ └── config.exs │ │ ├── lib │ │ ├── drop.ex │ │ └── function_maker.ex │ │ ├── mix.exs │ │ └── test │ │ ├── drop_test.exs │ │ └── test_helper.exs ├── ch15 │ └── fall │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config │ │ ├── config.exs │ │ ├── dev.exs │ │ ├── prod.exs │ │ └── test.exs │ │ ├── lib │ │ ├── fall.ex │ │ └── fall │ │ │ └── endpoint.ex │ │ ├── mix.exs │ │ ├── mix.lock │ │ ├── priv │ │ ├── gettext │ │ │ ├── en │ │ │ │ └── LC_MESSAGES │ │ │ │ │ └── errors.po │ │ │ └── errors.pot │ │ └── static │ │ │ ├── css │ │ │ └── app.css │ │ │ ├── favicon.ico │ │ │ ├── images │ │ │ └── phoenix.png │ │ │ ├── js │ │ │ ├── app.js │ │ │ └── phoenix.js │ │ │ └── robots.txt │ │ ├── test │ │ ├── controllers │ │ │ └── page_controller_test.exs │ │ ├── support │ │ │ ├── channel_case.ex │ │ │ └── conn_case.ex │ │ ├── test_helper.exs │ │ └── views │ │ │ ├── error_view_test.exs │ │ │ ├── layout_view_test.exs │ │ │ └── page_view_test.exs │ │ └── web │ │ ├── channels │ │ └── user_socket.ex │ │ ├── controllers │ │ ├── fall_controller.ex │ │ └── page_controller.ex │ │ ├── gettext.ex │ │ ├── router.ex │ │ ├── templates │ │ ├── fall │ │ │ ├── faller.html.eex │ │ │ └── welcome.html.eex │ │ ├── layout │ │ │ └── app.html.eex │ │ └── page │ │ │ └── index.html.eex │ │ ├── views │ │ ├── error_helpers.ex │ │ ├── error_view.ex │ │ ├── fall.ex │ │ ├── layout_view.ex │ │ └── page_view.ex │ │ └── web.ex └── files.txt └── README.md /1st-edition/appB/ex1-docs/combined/.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /deps 3 | erl_crash.dump 4 | *.ez 5 | -------------------------------------------------------------------------------- /1st-edition/appB/ex1-docs/combined/README.md: -------------------------------------------------------------------------------- 1 | Combined 2 | ======== 3 | 4 | ** TODO: Add description ** 5 | -------------------------------------------------------------------------------- /1st-edition/appB/ex1-docs/combined/docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | combined v0.0.1 Documentation 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /1st-edition/appB/ex1-docs/combined/mix.lock: -------------------------------------------------------------------------------- 1 | %{"ex_doc": {:git, "git://github.com/elixir-lang/ex_doc.git", "ca71b84b9c3c7e23b4b661e485a909aee3fdbc3b", []}, 2 | "hoedown": {:git, "git://github.com/hoedown/hoedown.git", "0610117f44b173a4e2112afb2f510156a32355b5", []}, 3 | "markdown": {:git, "git://github.com/devinus/markdown.git", "0345e2044ba71780ba02b2591f1017703d0fa148", []}} 4 | -------------------------------------------------------------------------------- /1st-edition/appB/ex1-docs/combined/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | 4 | test "the truth" do 5 | assert 1 + 1 == 2 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/appB/ex1-docs/combined/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /1st-edition/appB/ex1-docs/docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Drop v0.1 Documentation 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /1st-edition/ch02/ex1-drop/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | 6 | def mps_to_mph(mps) do 7 | 2.23693629 * mps 8 | end 9 | 10 | def mps_to_kph(mps) do 11 | 3.6 * mps 12 | end 13 | 14 | end 15 | 16 | 17 | -------------------------------------------------------------------------------- /1st-edition/ch02/ex2-split/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex2-split/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex3-combined/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Convert.mps_to_mph(Drop.fall_velocity(meters)) 4 | end 5 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex3-combined/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex3-combined/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex4-pipe/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Drop.fall_velocity(meters) |> Convert.mps_to_mph 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /1st-edition/ch02/ex4-pipe/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex4-pipe/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex5-import/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | 3 | import Convert 4 | 5 | def height_to_mph(meters) do 6 | mps_to_mph(Drop.fall_velocity(meters)) 7 | end 8 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex5-import/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /1st-edition/ch02/ex5-import/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | import :math, only: [sqrt: 1] 4 | sqrt(2 * 9.8 * distance) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /1st-edition/ch02/ex6-defaults/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance, gravity \\ 9.8) do 3 | :math.sqrt(2 * gravity * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex1-atoms/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(:earth, distance) do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | def fall_velocity(:moon, distance) do 8 | :math.sqrt(2 * 1.6 * distance) 9 | end 10 | 11 | def fall_velocity(:mars, distance) do 12 | :math.sqrt(2 * 3.71 * distance) 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex2-guards/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(:earth, distance) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | def fall_velocity(:moon, distance) when distance >= 0 do 8 | :math.sqrt(2 * 1.6 * distance) 9 | end 10 | 11 | def fall_velocity(:mars, distance) when distance >= 0 do 12 | :math.sqrt(2 * 3.71 * distance) 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex2-guards/mathDemo.ex: -------------------------------------------------------------------------------- 1 | defmodule MathDemo do 2 | 3 | def absolute_value(number) when number < 0 do 4 | -number 5 | end 6 | 7 | def absolute_value(number) when number == 0 do 8 | 0 9 | end 10 | 11 | def absolute_value(number) when number > 0 do 12 | number 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex3-underscore/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex3-underscore/drop2.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop2 do 2 | 3 | def fall_velocity(_, distance) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex4-tuples/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({:earth, distance}) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | def fall_velocity({:moon, distance}) when distance >= 0 do 8 | :math.sqrt(2 * 1.6 * distance) 9 | end 10 | 11 | def fall_velocity({:mars, distance}) when distance >= 0 do 12 | :math.sqrt(2 * 3.71 * distance) 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex5-tuplesMore/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({planemo, distance}) when distance >= 0 do 4 | fall_velocity(planemo, distance) 5 | end 6 | 7 | 8 | defp fall_velocity(:earth, distance) do 9 | :math.sqrt(2 * 9.8 * distance) 10 | end 11 | 12 | defp fall_velocity(:moon, distance) do 13 | :math.sqrt(2 * 1.6 * distance) 14 | end 15 | 16 | defp fall_velocity(:mars, distance) do 17 | :math.sqrt(2 * 3.71 * distance) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex5-tuplesMore/drop2.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop2 do 2 | 3 | def fall_velocity(where) do 4 | fall_velocity(elem(where,0), elem(where,1)) 5 | end 6 | 7 | 8 | defp fall_velocity(:earth, distance) do 9 | :math.sqrt(2 * 9.8 * distance) 10 | end 11 | 12 | defp fall_velocity(:moon, distance) do 13 | :math.sqrt(2 * 1.6 * distance) 14 | end 15 | 16 | defp fall_velocity(:mars, distance) do 17 | :math.sqrt(2 * 3.71 * distance) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /1st-edition/ch03/ex5-tuplesMore/drop3.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop3 do 2 | 3 | def fall_velocity(where) do 4 | {planemo, distance} = where 5 | fall_velocity(planemo,distance) 6 | end 7 | 8 | 9 | defp fall_velocity(:earth, distance) do 10 | :math.sqrt(2 * 9.8 * distance) 11 | end 12 | 13 | defp fall_velocity(:moon, distance) do 14 | :math.sqrt(2 * 1.6 * distance) 15 | end 16 | 17 | defp fall_velocity(:mars, distance) do 18 | :math.sqrt(2 * 3.71 * distance) 19 | end 20 | 21 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex1-case/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | case planemo do 5 | :earth -> :math.sqrt(2 * 9.8 * distance) 6 | :moon -> :math.sqrt(2 * 1.6 * distance) 7 | :mars -> :math.sqrt(2 * 3.71 * distance) 8 | end 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /1st-edition/ch04/ex10-factorial-down-instrumented/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) when n > 1 do 4 | IO.puts("Calling from #{n}.") 5 | result = n * factorial(n-1) 6 | IO.puts("#{n} yields #{result}.") 7 | result 8 | end 9 | 10 | def factorial(n) when n<=1 do 11 | IO.puts("Calling from 1.") 12 | IO.puts("1 yields 1.") 13 | 1 14 | end 15 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex11-factorial-up/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) do 4 | factorial(1,n,1) 5 | end 6 | 7 | defp factorial(current, n, result) when current <= n do 8 | new_result = result * current 9 | IO.puts("#{current} yields #{new_result}.") 10 | factorial(current+1, n, new_result) 11 | end 12 | 13 | defp factorial(_current, _n, result) do 14 | IO.puts("finished!") 15 | result 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /1st-edition/ch04/ex2-case/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex3-case/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) do 4 | gravity = case planemo do 5 | :earth when distance >= 0 -> 9.8 6 | :moon when distance >= 0 -> 1.6 7 | :mars when distance >= 0 -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex5-if/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | 10 | velocity = :math.sqrt(2 * gravity * distance) 11 | 12 | if velocity > 20 do 13 | IO.puts("Look out below!") 14 | else 15 | IO.puts("Reasonable...") 16 | end 17 | 18 | velocity 19 | 20 | end 21 | 22 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex6-broken/broken.ex: -------------------------------------------------------------------------------- 1 | defmodule Broken do 2 | 3 | def bad_cond(test_val) do 4 | 5 | cond do 6 | test_val < 0 -> x=1 7 | test_val >= 0 -> y=2 8 | end 9 | 10 | x+y 11 | 12 | end 13 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex7-countdown/count.ex: -------------------------------------------------------------------------------- 1 | defmodule Count do 2 | 3 | def countdown(from) when from > 0 do 4 | IO.puts(from) 5 | countdown(from-1) 6 | end 7 | 8 | def countdown(from) do 9 | IO.puts("blastoff!") 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex8-countup/count.ex: -------------------------------------------------------------------------------- 1 | defmodule Count do 2 | 3 | def countup(limit) do 4 | countup(1,limit) 5 | end 6 | 7 | defp countup(count, limit) when count <= limit do 8 | IO.puts(count) 9 | countup(count+1, limit) 10 | end 11 | 12 | defp countup(count, limit) do 13 | IO.puts("finished!") 14 | end 15 | 16 | end -------------------------------------------------------------------------------- /1st-edition/ch04/ex9-factorial-down/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) when n > 1 do 4 | n * factorial(n-1) 5 | end 6 | 7 | def factorial(n) when n<=1 do 8 | 1 9 | end 10 | end -------------------------------------------------------------------------------- /1st-edition/ch05/ex1-ask/ask.ex: -------------------------------------------------------------------------------- 1 | defmodule Ask do 2 | 3 | def chars() do 4 | IO.puts( 5 | """ 6 | Which planemo are you on? 7 | 1. Earth 8 | 2. Moon 9 | 3. Mars 10 | """ 11 | ) 12 | 13 | IO.getn("Which? > ") 14 | 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /1st-edition/ch05/ex2-ask/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /1st-edition/ch06/ex1-product/overall.ex: -------------------------------------------------------------------------------- 1 | defmodule Overall do 2 | def product([]) do 3 | 0 4 | end 5 | 6 | def product(list) do 7 | product(list, 1) 8 | end 9 | 10 | def product([], accumulated_product) do 11 | accumulated_product 12 | end 13 | 14 | def product([head | tail], accumulated_product) do 15 | product(tail, head * accumulated_product) 16 | end 17 | end 18 | 19 | -------------------------------------------------------------------------------- /1st-edition/ch06/ex2-drop/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity({planemo, distance}) do 3 | fall_velocity(planemo, distance) 4 | end 5 | 6 | def fall_velocity(:earth, distance) when distance >= 0 do 7 | :math.sqrt(2 * 9.8 * distance) 8 | end 9 | 10 | def fall_velocity(:moon, distance) when distance >= 0 do 11 | :math.sqrt(2 * 1.6 * distance) 12 | end 13 | 14 | def fall_velocity(:mars, distance) when distance >= 0 do 15 | :math.sqrt(2 * 3.71 * distance) 16 | end 17 | end 18 | 19 | -------------------------------------------------------------------------------- /1st-edition/ch06/ex2-drop/listdrop.ex: -------------------------------------------------------------------------------- 1 | defmodule ListDrop do 2 | def falls(list) do 3 | falls(list, []) 4 | end 5 | 6 | def falls([], results) do 7 | results 8 | end 9 | 10 | def falls([head|tail], results) do 11 | falls(tail, [Drop.fall_velocity(head) | results]) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /1st-edition/ch06/ex3-drop/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity({planemo, distance}) do 3 | fall_velocity(planemo, distance) 4 | end 5 | 6 | def fall_velocity(:earth, distance) when distance >= 0 do 7 | :math.sqrt(2 * 9.8 * distance) 8 | end 9 | 10 | def fall_velocity(:moon, distance) when distance >= 0 do 11 | :math.sqrt(2 * 1.6 * distance) 12 | end 13 | 14 | def fall_velocity(:mars, distance) when distance >= 0 do 15 | :math.sqrt(2 * 3.71 * distance) 16 | end 17 | end 18 | 19 | -------------------------------------------------------------------------------- /1st-edition/ch06/ex3-drop/listdrop.ex: -------------------------------------------------------------------------------- 1 | defmodule ListDrop do 2 | def falls(list) do 3 | falls(list, []) 4 | end 5 | 6 | def falls([], results) do 7 | Enum.reverse(results) 8 | end 9 | 10 | def falls([head|tail], results) do 11 | falls(tail, [Drop.fall_velocity(head) | results]) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex1-struct/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex1-struct/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end 4 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex2-struct-match/struct_drop.ex: -------------------------------------------------------------------------------- 1 | defmodule StructDrop do 2 | 3 | def fall_velocity(t) do 4 | fall_velocity(t.planemo, t.height) 5 | end 6 | 7 | def fall_velocity(:earth, distance) when distance >= 0 do 8 | :math.sqrt(2 * 9.8 * distance) 9 | end 10 | 11 | def fall_velocity(:moon, distance) when distance >= 0 do 12 | :math.sqrt(2 * 1.6 * distance) 13 | end 14 | 15 | def fall_velocity(:mars, distance) when distance >= 0 do 16 | :math.sqrt(2 * 3.71 * distance) 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex2-struct-match/structs.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defmodule Tower do 6 | defstruct location: "", height: 20, planemo: :earth, name: "" 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex3-struct-components/structs.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defmodule Tower do 6 | defstruct location: "", height: 20, planemo: :earth, name: "" 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex4-struct-multi/structs.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defmodule Tower do 6 | defstruct location: "", height: 20, planemo: :earth, name: "" 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex5-protocol/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defimpl Valid, for: Planemo do 6 | def valid?(p) do 7 | p.gravity >= 0 && p.diameter >= 0 && 8 | p.distance_from_sun >= 0 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex5-protocol/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end 4 | 5 | defimpl Valid, for: Tower do 6 | def valid?(%Tower{height: h, planemo: p}) do 7 | h >= 0 && p != nil 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex5-protocol/valid_protocol.ex: -------------------------------------------------------------------------------- 1 | defprotocol Valid do 2 | @doc "Returns true if data is considered nominally valid" 3 | def valid?(data) 4 | end 5 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex6-protocol/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defimpl Valid, for: Planemo do 6 | def valid?(p) do 7 | p.gravity >= 0 && p.diameter >= 0 && 8 | p.distance_from_sun >= 0 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex6-protocol/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end 4 | 5 | defimpl Valid, for: Tower do 6 | def valid?(%Tower{height: h, planemo: p}) do 7 | h >= 0 && p != nil 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex6-protocol/valid_protocol.ex: -------------------------------------------------------------------------------- 1 | defprotocol Valid do 2 | @doc "Returns true if data is considered nominally valid" 3 | def valid?(data) 4 | end 5 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex7-inspect/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defimpl Valid, for: Planemo do 6 | def valid?(p) do 7 | p.gravity >= 0 && p.diameter >= 0 && 8 | p.distance_from_sun >= 0 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /1st-edition/ch07/ex7-inspect/valid_protocol.ex: -------------------------------------------------------------------------------- 1 | defprotocol Valid do 2 | @doc "Returns true if data is considered nominally valid" 3 | def valid?(data) 4 | end 5 | -------------------------------------------------------------------------------- /1st-edition/ch08/ex1-hof/hof.ex: -------------------------------------------------------------------------------- 1 | defmodule Hof do 2 | def tripler(value, function) do 3 | 3 * function.(value) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex1-simple/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report do 3 | receive do 4 | msg -> IO.puts("Received #{msg}") 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex2-recursion/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report do 3 | receive do 4 | msg -> IO.puts("Received #{msg}") 5 | report() 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex3-counter/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report(count) do 3 | receive do 4 | msg -> IO.puts("Received #{count}: #{msg}") 5 | report(count + 1) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex3-counter/ttb_last_config: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/1st-edition/ch09/ex3-counter/ttb_last_config -------------------------------------------------------------------------------- /1st-edition/ch09/ex3-debug/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) do 4 | factorial(1, n, 1) 5 | end 6 | 7 | def factorial(current, n, result) when current <= n do 8 | new_result = result * current 9 | IO.puts("#{current} yields #{new_result}!") 10 | factorial(current + 1, n, new_result) 11 | end 12 | 13 | def factorial(_current, _n, result) do 14 | IO.puts("Finished.") 15 | result 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex4-state/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report(count) do 3 | new_count = receive do 4 | msg -> IO.puts("Received #{count}: #{msg}") 5 | count + 1 6 | end 7 | report(new_count) 8 | end 9 | end -------------------------------------------------------------------------------- /1st-edition/ch09/ex4-testing/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.71 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex4-testing/drop_bad.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.41 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex4-testing/drop_test.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start 2 | 3 | defmodule DropTest do 4 | use ExUnit.Case, async: true 5 | 6 | test "Zero distance gives zero velocity" do 7 | assert Drop.fall_velocity(:earth,0) == 0 8 | end 9 | 10 | test "Mars calculation correct" do 11 | assert Drop.fall_velocity(:mars, 10) == :math.sqrt(2 * 3.71 * 10) 12 | end 13 | end 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /1st-edition/ch09/ex5-division/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report do 3 | receive do 4 | x -> IO.puts("Divided to #{x / 2}") 5 | report() 6 | end 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /1st-edition/ch10/ex1-tryCatch/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.71 7 | end 8 | try do 9 | :math.sqrt(2 * gravity * distance) 10 | rescue 11 | _error -> _error 12 | end 13 | end 14 | end -------------------------------------------------------------------------------- /1st-edition/ch10/ex1-tryCatch/drop2.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | try do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | rescue 11 | _error -> _error 12 | end 13 | end 14 | end -------------------------------------------------------------------------------- /1st-edition/ch10/ex1-tryCatch/drop3.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | try do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | rescue 11 | ArithmeticError -> {:error, "Distance must be non-negative"} 12 | CaseClauseError -> {:error, "Unknown planemo #{planemo}"} 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /1st-edition/ch10/ex3-debug/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) do 4 | factorial(1, n, 1) 5 | end 6 | 7 | def factorial(current, n, result) when current <= n do 8 | new_result = result * current 9 | IO.puts("#{current} yields #{new_result}!") 10 | factorial(current + 1, n, new_result) 11 | end 12 | 13 | def factorial(_current, _n, result) do 14 | IO.puts("Finished.") 15 | result 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /1st-edition/ch10/ex4-testing/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.71 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /1st-edition/ch10/ex4-testing/drop_bad.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.41 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /1st-edition/ch10/ex4-testing/drop_test.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start 2 | 3 | defmodule DropTest do 4 | use ExUnit.Case, async: true 5 | 6 | test "Zero distance gives zero velocity" do 7 | assert Drop.fall_velocity(:earth,0) == 0 8 | end 9 | 10 | test "Mars calculation correct" do 11 | assert Drop.fall_velocity(:mars, 10) == :math.sqrt(2 * 3.71 * 10) 12 | end 13 | end 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex1-records/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, Tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex1-records/user.ex: -------------------------------------------------------------------------------- 1 | defmodule User do 2 | require Record; 3 | Record.defrecord :user, [name: "José", age: "25"] 4 | end -------------------------------------------------------------------------------- /1st-edition/ch11/ex2-records/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, Tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex3-records/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, Tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex4-records/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, Tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex5-ets/planemo_storage.ex: -------------------------------------------------------------------------------- 1 | defmodule PlanemoStorage do 2 | require Planemo 3 | 4 | def setup do 5 | planemo_table = :ets.new(:planemos,[:named_table, 6 | {:keypos, Planemo.planemo(:name) + 1}]) 7 | :ets.info planemo_table 8 | end 9 | end -------------------------------------------------------------------------------- /1st-edition/ch11/ex5-ets/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex6-ets/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex7-ets-calculator/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex8-mnesia/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0] 4 | end 5 | 6 | defmodule Tower do 7 | require Record 8 | Record.defrecord :tower, Tower, [location: "", height: 20, planemo: :earth, name: ""] 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex9-qlc/records.ex: -------------------------------------------------------------------------------- 1 | defrecord Planemo, name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 2 | defrecord Tower, location: "", height: 20, planemo: :earth, name: "" 3 | -------------------------------------------------------------------------------- /1st-edition/ch11/ex9-qlc/test.ex: -------------------------------------------------------------------------------- 1 | defmodule Test do 2 | 3 | def setup do 4 | :mnesia.start() 5 | :mnesia.transaction( 6 | fn() -> 7 | :qlc.e( 8 | :qlc.q( lc x inlist :mnesia.table(planemo), do: x ) 9 | ) end ) 10 | end 11 | end 12 | 13 | 14 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex1-drop/testor.ex: -------------------------------------------------------------------------------- 1 | defmodule Testor do 2 | def __struct__ do 3 | %{} 4 | end 5 | end 6 | 7 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex2-drop-sup/drop_sup.ex: -------------------------------------------------------------------------------- 1 | defmodule DropSup do 2 | use Supervisor 3 | 4 | # convenience method for startup 5 | 6 | def start_link do 7 | Supervisor.start_link(__MODULE__, [], [{:name, __MODULE__}]) 8 | end 9 | 10 | # supervisor callback 11 | 12 | def init([]) do 13 | child = [worker(DropServer, [], [])] # {:name, DropServer} 14 | supervise(child, [{:strategy, :one_for_one}, {:max_restarts, 1}, 15 | {:max_seconds, 5}]) 16 | end 17 | 18 | # Internal functions (none here) 19 | end 20 | 21 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app/drop_app/.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /deps 3 | erl_crash.dump 4 | *.ez 5 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app/drop_app/README.md: -------------------------------------------------------------------------------- 1 | DropApp 2 | ======= 3 | 4 | ** TODO: Add description ** 5 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app/drop_app/lib/drop_app.ex: -------------------------------------------------------------------------------- 1 | defmodule DropApp do 2 | use Application 3 | 4 | def start(_type, _args) do 5 | IO.puts("Starting the app...") # show that app is really starting. 6 | DropSup.start_link() 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app/drop_app/test/drop_app_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropAppTest do 2 | use ExUnit.Case 3 | 4 | test "the truth" do 5 | assert 1 + 1 == 2 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app/drop_app/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app2/drop_app/.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /deps 3 | erl_crash.dump 4 | *.ez 5 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app2/drop_app/README.md: -------------------------------------------------------------------------------- 1 | DropApp 2 | ======= 3 | 4 | ** TODO: Add description ** 5 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app2/drop_app/lib/drop_app.ex: -------------------------------------------------------------------------------- 1 | defmodule DropApp do 2 | use Application 3 | 4 | def start(_type, _args) do 5 | IO.puts("Starting the app...") # show that app is really starting. 6 | DropSup.start_link() 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app2/drop_app/test/drop_app_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropAppTest do 2 | use ExUnit.Case 3 | 4 | test "the truth" do 5 | assert 1 + 1 == 2 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/ch12/ex3-drop-app2/drop_app/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex1-difference/difference.ex: -------------------------------------------------------------------------------- 1 | defmodule Difference do 2 | 3 | defmacro m_test(x) do 4 | IO.puts("#{inspect(x)}") 5 | x 6 | end 7 | 8 | def f_test(x) do 9 | IO.puts("#{inspect(x)}") 10 | x 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex2-double/double.ex: -------------------------------------------------------------------------------- 1 | defmodule Double do 2 | 3 | defmacro double x do 4 | {:*, [], [2, x]} 5 | end 6 | 7 | end 8 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex3-double/double.ex: -------------------------------------------------------------------------------- 1 | defmodule Double do 2 | 3 | defmacro double(x) do 4 | quote do 5 | 2 * unquote(x) 6 | end 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex4-unless/logic.ex: -------------------------------------------------------------------------------- 1 | defmodule Logic do 2 | 3 | defmacro unless(condition, options) do 4 | quote do 5 | if(!unquote(condition), unquote(options)) 6 | end 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex5-programmatic/function_maker.ex: -------------------------------------------------------------------------------- 1 | defmodule FunctionMaker do 2 | defmacro create_multiplier(function_name, factor) do 3 | quote do 4 | def unquote(function_name)(value) do 5 | unquote(factor) * value 6 | end 7 | end 8 | end 9 | end 10 | 11 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex5-programmatic/multiply.ex: -------------------------------------------------------------------------------- 1 | defmodule Multiply do 2 | require FunctionMaker 3 | 4 | FunctionMaker.create_multiplier(:double, 2) 5 | FunctionMaker.create_multiplier(:triple, 3) 6 | 7 | def example do 8 | x = triple(12) 9 | IO.puts("Twelve times 3 is #{x}") 10 | end 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex6-multidrop/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | require FunctionMaker 3 | 4 | FunctionMaker.create_functions([{:mercury, 3.7}, {:venus, 8.9}, 5 | {:earth, 9.8}, {:moon, 1.6}, {:mars, 3.7}, 6 | {:jupiter, 23.1}, {:saturn, 9.0}, {:uranus, 8.7}, 7 | {:neptune, 11.0}, {:pluto, 0.6}]) 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /1st-edition/ch13/ex6-multidrop/function_maker.ex: -------------------------------------------------------------------------------- 1 | defmodule FunctionMaker do 2 | defmacro create_functions(planemo_list) do 3 | Enum.map planemo_list, fn {name, gravity} -> 4 | quote do 5 | def unquote(:"#{name}_drop")(distance) do 6 | :math.sqrt(2 * unquote(gravity) * distance) 7 | end 8 | end 9 | end 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/builder.pl: -------------------------------------------------------------------------------- 1 | use File::Find; 2 | 3 | find(\&wanted, '.'); 4 | 5 | sub wanted 6 | { 7 | if ($_ eq 'mix.exs') 8 | { 9 | print($File::Find::dir, "\n"); 10 | system('mix compile'); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex1-drop/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex1-drop/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex1-drop/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | 6 | def mps_to_mph(mps) do 7 | 2.23693629 * mps 8 | end 9 | 10 | def mps_to_kph(mps) do 11 | 3.6 * mps 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex1-drop/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex1-drop/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex10-doc-specs/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex10-doc-specs/lib/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Convert.mps_to_mph(Drop.fall_velocity(meters)) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex10-doc-specs/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex10-doc-specs/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | @doc """ 3 | Calculates the velocity of an object falling on Earth 4 | as if it were in a vacuum (no air resistance). The distance is 5 | the height from which the object falls, specified in meters, 6 | and the function returns a velocity in meters per second. 7 | """ 8 | @spec fall_velocity(number()) :: number() 9 | 10 | def fall_velocity(distance) do 11 | import :math, only: [sqrt: 1] 12 | 13 | sqrt(2 * 9.8 * distance) 14 | end 15 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex10-doc-specs/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex10-doc-specs/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex11-doc-module/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex11-doc-module/lib/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Convert.mps_to_mph(Drop.fall_velocity(meters)) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex11-doc-module/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex11-doc-module/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex11-doc-module/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex2-split/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex2-split/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex2-split/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex2-split/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex2-split/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex2-split/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex3-combined/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex3-combined/lib/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Convert.mps_to_mph(Drop.fall_velocity(meters)) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex3-combined/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex3-combined/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex3-combined/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex3-combined/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4-combined/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4-combined/lib/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Convert.mps_to_mph(Drop.fall_velocity(meters)) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4-combined/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4-combined/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4-combined/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4-combined/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4a-pipe/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4a-pipe/lib/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Drop.fall_velocity(meters) |> Convert.mps_to_mph 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4a-pipe/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4a-pipe/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4a-pipe/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex4a-pipe/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import-erlang/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import-erlang/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import-erlang/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | import :math 3 | 4 | def fall_velocity(distance) do 5 | sqrt(2 * 9.8 * distance) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import-erlang/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import-erlang/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import/lib/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | import Convert 3 | def height_to_mph(meters) do 4 | mps_to_mph(Drop.fall_velocity(meters)) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex5-import/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex6-defaults/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex6-defaults/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex6-defaults/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance, gravity \\ 9.8) do 3 | :math.sqrt(2 * gravity * distance) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex6-defaults/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex6-defaults/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex7-docs/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex7-docs/lib/combined.ex: -------------------------------------------------------------------------------- 1 | # convenience functions! 2 | defmodule Combined do 3 | def height_to_mph(meters) do #takes meters, returns miles per hour 4 | Convert.mps_to_mph(Drop.fall_velocity(meters)) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex7-docs/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex7-docs/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(distance) do 3 | :math.sqrt(2 * 9.8 * distance) 4 | end 5 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex7-docs/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex7-docs/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex8-doc-function/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex8-doc-function/lib/combined.ex: -------------------------------------------------------------------------------- 1 | defmodule Combined do 2 | def height_to_mph(meters) do 3 | Convert.mps_to_mph(Drop.fall_velocity(meters)) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex8-doc-function/lib/convert.ex: -------------------------------------------------------------------------------- 1 | defmodule Convert do 2 | def mps_to_mph(mps) do 3 | 2.23693629 * mps 4 | end 5 | 6 | def mps_to_kph(mps) do 7 | 3.6 * mps 8 | end 9 | end -------------------------------------------------------------------------------- /2nd-edition/ch02/ex8-doc-function/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | @doc """ 3 | Calculates the velocity of an object falling on Earth 4 | as if it were in a vacuum (no air resistance). The distance is 5 | the height from which the object falls, specified in meters, 6 | and the function returns a velocity in meters per second. 7 | """ 8 | 9 | def fall_velocity(distance) do 10 | import :math, only: [sqrt: 1] 11 | 12 | sqrt(2 * 9.8 * distance) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex8-doc-function/test/combined_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CombinedTest do 2 | use ExUnit.Case 3 | doctest Combined 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch02/ex8-doc-function/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-1/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-1/lib/math_demo.ex: -------------------------------------------------------------------------------- 1 | defmodule MathDemo do 2 | 3 | def absolute_value(number) when number < 0 do 4 | -number 5 | end 6 | 7 | def absolute_value(number) when number == 0 do 8 | 0 9 | end 10 | 11 | def absolute_value(number) when number > 0 do 12 | number 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-1/test/math_demo_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MathDemoTest do 2 | use ExUnit.Case 3 | doctest MathDemo 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-1/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-2/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-2/lib/math_demo.ex: -------------------------------------------------------------------------------- 1 | defmodule MathDemo do 2 | end 3 | -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-2/test/math_demo_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MathDemoTest do 2 | use ExUnit.Case 3 | doctest MathDemo 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch03/absolute-value-2/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex1-atoms/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex1-atoms/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex1-atoms/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(:earth, distance) do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | def fall_velocity(:moon, distance) do 8 | :math.sqrt(2 * 1.6 * distance) 9 | end 10 | 11 | def fall_velocity(:mars, distance) do 12 | :math.sqrt(2 * 3.71 * distance) 13 | end 14 | 15 | def fall_velocity(:jupiter, distance) do 16 | :math.sqrt(2 * 25.3 * distance) 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex1-atoms/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex1-atoms/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex2-guards/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex2-guards/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex2-guards/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(:earth, distance) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | def fall_velocity(:moon, distance) when distance >= 0 do 8 | :math.sqrt(2 * 1.6 * distance) 9 | end 10 | 11 | def fall_velocity(:mars, distance) when distance >= 0 do 12 | :math.sqrt(2 * 3.71 * distance) 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /2nd-edition/ch03/ex2-guards/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex2-guards/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex3-underscore/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex3-underscore/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex3-underscore/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | end -------------------------------------------------------------------------------- /2nd-edition/ch03/ex3-underscore/lib/drop2.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop2 do 2 | 3 | def fall_velocity(_, distance) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | end -------------------------------------------------------------------------------- /2nd-edition/ch03/ex3-underscore/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex3-underscore/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex4-tuples/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex4-tuples/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex4-tuples/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({:earth, distance}) when distance >= 0 do 4 | :math.sqrt(2 * 9.8 * distance) 5 | end 6 | 7 | def fall_velocity({:moon, distance}) when distance >= 0 do 8 | :math.sqrt(2 * 1.6 * distance) 9 | end 10 | 11 | def fall_velocity({:mars, distance}) when distance >= 0 do 12 | :math.sqrt(2 * 3.71 * distance) 13 | end 14 | 15 | end -------------------------------------------------------------------------------- /2nd-edition/ch03/ex4-tuples/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex4-tuples/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex5-tuplesMore/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex5-tuplesMore/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex5-tuplesMore/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({planemo, distance}) when distance >= 0 do 4 | fall_velocity(planemo, distance) 5 | end 6 | 7 | 8 | defp fall_velocity(:earth, distance) do 9 | :math.sqrt(2 * 9.8 * distance) 10 | end 11 | 12 | defp fall_velocity(:moon, distance) do 13 | :math.sqrt(2 * 1.6 * distance) 14 | end 15 | 16 | defp fall_velocity(:mars, distance) do 17 | :math.sqrt(2 * 3.71 * distance) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /2nd-edition/ch03/ex5-tuplesMore/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch03/ex5-tuplesMore/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | case planemo do 5 | :earth -> :math.sqrt(2 * 9.8 * distance) 6 | :moon -> :math.sqrt(2 * 1.6 * distance) 7 | :mars -> :math.sqrt(2 * 3.71 * distance) 8 | end 9 | end 10 | 11 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/xbuild/dev/consolidated/.compile.protocols: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch04/ex1-case/xbuild/dev/consolidated/.compile.protocols -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/xbuild/dev/lib/drop/.compile.elixir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch04/ex1-case/xbuild/dev/lib/drop/.compile.elixir -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/xbuild/dev/lib/drop/.compile.elixir_scm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch04/ex1-case/xbuild/dev/lib/drop/.compile.elixir_scm -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/xbuild/dev/lib/drop/.compile.xref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch04/ex1-case/xbuild/dev/lib/drop/.compile.xref -------------------------------------------------------------------------------- /2nd-edition/ch04/ex1-case/xbuild/dev/lib/drop/ebin/drop.app: -------------------------------------------------------------------------------- 1 | {application,drop, 2 | [{registered,[]}, 3 | {description,"drop"}, 4 | {vsn,"0.1.0"}, 5 | {modules,['Elixir.Drop']}, 6 | {applications,[kernel,stdlib,elixir,logger]}]}. -------------------------------------------------------------------------------- /2nd-edition/ch04/ex10-factorial-down-instrumented/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex10-factorial-down-instrumented/lib/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) when n > 1 do 4 | IO.puts("Calling from #{n}.") 5 | result = n * factorial(n - 1) 6 | IO.puts("#{n} yields #{result}.") 7 | result 8 | end 9 | 10 | def factorial(n) when n <= 1 do 11 | IO.puts("Calling from 1.") 12 | IO.puts("1 yields 1.") 13 | 1 14 | end 15 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex10-factorial-down-instrumented/test/fact_test.exs: -------------------------------------------------------------------------------- 1 | defmodule FactTest do 2 | use ExUnit.Case 3 | doctest Fact 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex10-factorial-down-instrumented/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-down-tail-recursive/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-down-tail-recursive/lib/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) do 4 | factorial(n, 1) 5 | end 6 | 7 | defp factorial(current, result) when current > 1 do 8 | new_result = current * result 9 | IO.puts("#{current} yields #{new_result}.") 10 | factorial(current - 1, new_result) 11 | end 12 | 13 | defp factorial(_current, result) do 14 | IO.puts("finished!") 15 | result 16 | end 17 | 18 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-down-tail-recursive/test/fact_test.exs: -------------------------------------------------------------------------------- 1 | defmodule FactTest do 2 | use ExUnit.Case 3 | doctest Fact 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-down-tail-recursive/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-up/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-up/README.md: -------------------------------------------------------------------------------- 1 | # Fact 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `fact` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:fact, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `fact` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:fact]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-up/lib/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) do 4 | factorial(1, n, 1) 5 | end 6 | 7 | defp factorial(current, n, result) when current <= n do 8 | new_result = result * current 9 | IO.puts("#{current} yields #{new_result}.") 10 | factorial(current + 1, n, new_result) 11 | end 12 | 13 | defp factorial(_current, _n, result) do 14 | IO.puts("finished!") 15 | result 16 | end 17 | 18 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-up/test/fact_test.exs: -------------------------------------------------------------------------------- 1 | defmodule FactTest do 2 | use ExUnit.Case 3 | doctest Fact 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex11-factorial-up/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex2-case/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex2-case/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex2-case/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex2-case/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex2-case/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex3-case/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex3-case/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex3-case/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) do 4 | gravity = case planemo do 5 | :earth when distance >= 0 -> 9.8 6 | :moon when distance >= 0 -> 1.6 7 | :mars when distance >= 0 -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | end 11 | 12 | end 13 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex3-case/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex3-case/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex4-cond/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex4-cond/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex4-cond/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex4-cond/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex5-if/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex5-if/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex5-if/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity(planemo, distance) when distance >= 0 do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | 10 | velocity = :math.sqrt(2 * gravity * distance) 11 | 12 | if velocity > 20 do 13 | IO.puts("Look out below!") 14 | else 15 | IO.puts("Reasonable...") 16 | end 17 | 18 | velocity 19 | 20 | end 21 | 22 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex5-if/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex5-if/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex6-broken/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex6-broken/lib/broken.ex: -------------------------------------------------------------------------------- 1 | defmodule Broken do 2 | 3 | def bad_cond(test_val) do 4 | 5 | cond do 6 | test_val < 0 -> x=1 7 | test_val >= 0 -> y=2 8 | end 9 | 10 | x+y 11 | 12 | end 13 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex6-broken/test/broken_test.exs: -------------------------------------------------------------------------------- 1 | defmodule BrokenTest do 2 | use ExUnit.Case 3 | doctest Broken 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex6-broken/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex7-countdown/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex7-countdown/lib/count.ex: -------------------------------------------------------------------------------- 1 | defmodule Count do 2 | 3 | def countdown(from) when from > 0 do 4 | IO.inspect(from) 5 | countdown(from-1) 6 | end 7 | 8 | def countdown(from) do 9 | IO.puts("blastoff!") 10 | end 11 | 12 | end 13 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex7-countdown/test/count_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CountTest do 2 | use ExUnit.Case 3 | doctest Count 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex7-countdown/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex8-countup/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex8-countup/lib/count.ex: -------------------------------------------------------------------------------- 1 | defmodule Count do 2 | 3 | def countup(limit) do 4 | countup(1,limit) 5 | end 6 | 7 | defp countup(count, limit) when count <= limit do 8 | IO.inspect(count) 9 | countup(count+1, limit) 10 | end 11 | 12 | # use underscore to avoid "unused variable" warnings 13 | 14 | defp countup(_count, _limit) do 15 | IO.puts("finished!") 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex8-countup/test/count_test.exs: -------------------------------------------------------------------------------- 1 | defmodule CountTest do 2 | use ExUnit.Case 3 | doctest Count 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex8-countup/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex9-factorial-down/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex9-factorial-down/lib/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) when n > 1 do 4 | n * factorial(n-1) 5 | end 6 | 7 | def factorial(n) when n <= 1 do 8 | 1 9 | end 10 | end -------------------------------------------------------------------------------- /2nd-edition/ch04/ex9-factorial-down/test/fact_test.exs: -------------------------------------------------------------------------------- 1 | defmodule FactTest do 2 | use ExUnit.Case 3 | doctest Fact 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch04/ex9-factorial-down/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex1-ask/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex1-ask/README.md: -------------------------------------------------------------------------------- 1 | # Ask 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `ask` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:ask, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `ask` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:ask]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex1-ask/lib/ask.ex: -------------------------------------------------------------------------------- 1 | defmodule Ask do 2 | 3 | def chars() do 4 | IO.puts(""" 5 | Which planemo are you on? 6 | 1. Earth 7 | 2. Moon 8 | 3. Mars 9 | """) 10 | 11 | IO.getn("Which? > ") 12 | 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex1-ask/test/ask_test.exs: -------------------------------------------------------------------------------- 1 | defmodule AskTest do 2 | use ExUnit.Case 3 | doctest Ask 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex1-ask/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex2-ask/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex2-ask/README.md: -------------------------------------------------------------------------------- 1 | # Ask 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `ask` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:ask, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `ask` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:ask]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex2-ask/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({planemo, distance}) when distance >= 0 do 4 | fall_velocity(planemo, distance) 5 | end 6 | 7 | 8 | defp fall_velocity(:earth, distance) do 9 | :math.sqrt(2 * 9.8 * distance) 10 | end 11 | 12 | defp fall_velocity(:moon, distance) do 13 | :math.sqrt(2 * 1.6 * distance) 14 | end 15 | 16 | defp fall_velocity(:mars, distance) do 17 | :math.sqrt(2 * 3.71 * distance) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /2nd-edition/ch05/ex2-ask/test/ask_test.exs: -------------------------------------------------------------------------------- 1 | defmodule AskTest do 2 | use ExUnit.Case 3 | doctest Ask 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex2-ask/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex3-ask/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex3-ask/README.md: -------------------------------------------------------------------------------- 1 | # Ask 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `ask` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:ask, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `ask` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:ask]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex3-ask/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({planemo, distance}) when distance >= 0 do 4 | fall_velocity(planemo, distance) 5 | end 6 | 7 | 8 | defp fall_velocity(:earth, distance) do 9 | :math.sqrt(2 * 9.8 * distance) 10 | end 11 | 12 | defp fall_velocity(:moon, distance) do 13 | :math.sqrt(2 * 1.6 * distance) 14 | end 15 | 16 | defp fall_velocity(:mars, distance) do 17 | :math.sqrt(2 * 3.71 * distance) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /2nd-edition/ch05/ex3-ask/test/ask_test.exs: -------------------------------------------------------------------------------- 1 | defmodule AskTest do 2 | use ExUnit.Case 3 | doctest Ask 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch05/ex3-ask/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex1-product/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex1-product/lib/overall.ex: -------------------------------------------------------------------------------- 1 | defmodule Overall do 2 | def product([]) do 3 | 0 4 | end 5 | 6 | def product(list) do 7 | product(list, 1) 8 | end 9 | 10 | def product([], accumulated_product) do 11 | accumulated_product 12 | end 13 | 14 | def product([head | tail], accumulated_product) do 15 | product(tail, head * accumulated_product) 16 | end 17 | end -------------------------------------------------------------------------------- /2nd-edition/ch06/ex1-product/test/overall_test.exs: -------------------------------------------------------------------------------- 1 | defmodule OverallTest do 2 | use ExUnit.Case 3 | doctest Overall 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex1-product/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex2-drop/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex2-drop/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({planemo, distance}) when distance >= 0 do 4 | fall_velocity(planemo, distance) 5 | end 6 | 7 | 8 | defp fall_velocity(:earth, distance) do 9 | :math.sqrt(2 * 9.8 * distance) 10 | end 11 | 12 | defp fall_velocity(:moon, distance) do 13 | :math.sqrt(2 * 1.6 * distance) 14 | end 15 | 16 | defp fall_velocity(:mars, distance) do 17 | :math.sqrt(2 * 3.71 * distance) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /2nd-edition/ch06/ex2-drop/lib/list_drop.ex: -------------------------------------------------------------------------------- 1 | defmodule ListDrop do 2 | def falls(list) do 3 | falls(list, []) 4 | end 5 | 6 | def falls([], results) do 7 | results 8 | end 9 | 10 | def falls([head|tail], results) do 11 | falls(tail, [Drop.fall_velocity(head) | results]) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex2-drop/test/list_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule ListDropTest do 2 | use ExUnit.Case 3 | doctest ListDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex2-drop/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex3-drop/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex3-drop/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | 3 | def fall_velocity({planemo, distance}) when distance >= 0 do 4 | fall_velocity(planemo, distance) 5 | end 6 | 7 | 8 | defp fall_velocity(:earth, distance) do 9 | :math.sqrt(2 * 9.8 * distance) 10 | end 11 | 12 | defp fall_velocity(:moon, distance) do 13 | :math.sqrt(2 * 1.6 * distance) 14 | end 15 | 16 | defp fall_velocity(:mars, distance) do 17 | :math.sqrt(2 * 3.71 * distance) 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /2nd-edition/ch06/ex3-drop/lib/list_drop.ex: -------------------------------------------------------------------------------- 1 | defmodule ListDrop do 2 | end 3 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex3-drop/test/list_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule ListDropTest do 2 | use ExUnit.Case 3 | doctest ListDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex3-drop/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex4-pascal/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex4-pascal/test/pascal_test.exs: -------------------------------------------------------------------------------- 1 | defmodule PascalTest do 2 | use ExUnit.Case 3 | doctest Pascal 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch06/ex4-pascal/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex1-struct/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex1-struct/lib/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex1-struct/lib/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex1-struct/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex1-struct/test/tower_test.exs: -------------------------------------------------------------------------------- 1 | defmodule TowerTest do 2 | use ExUnit.Case 3 | doctest Tower 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex2-struct-match/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex2-struct-match/lib/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex2-struct-match/lib/struct_drop.ex: -------------------------------------------------------------------------------- 1 | defmodule StructDrop do 2 | 3 | def fall_velocity(t = %Tower{}) do 4 | fall_velocity(t.planemo, t.height) 5 | end 6 | 7 | def fall_velocity(:earth, distance) when distance >= 0 do 8 | :math.sqrt(2 * 9.8 * distance) 9 | end 10 | 11 | def fall_velocity(:moon, distance) when distance >= 0 do 12 | :math.sqrt(2 * 1.6 * distance) 13 | end 14 | 15 | def fall_velocity(:mars, distance) when distance >= 0 do 16 | :math.sqrt(2 * 3.71 * distance) 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex2-struct-match/lib/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex2-struct-match/test/struct_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule StructDropTest do 2 | use ExUnit.Case 3 | doctest StructDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex2-struct-match/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex3-struct-components/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex3-struct-components/lib/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex3-struct-components/lib/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex3-struct-components/test/struct_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule StructDropTest do 2 | use ExUnit.Case 3 | doctest StructDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex3-struct-components/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex4-struct-multi/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex4-struct-multi/lib/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex4-struct-multi/lib/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex4-struct-multi/test/struct_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule StructDropTest do 2 | use ExUnit.Case 3 | doctest StructDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex4-struct-multi/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex5-protocol/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex5-protocol/lib/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defimpl Valid, for: Planemo do 6 | def valid?(p) do 7 | p.gravity >= 0 && p.diameter >= 0 && 8 | p.distance_from_sun >= 0 9 | end 10 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex5-protocol/lib/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex5-protocol/lib/valid.ex: -------------------------------------------------------------------------------- 1 | defprotocol Valid do 2 | @doc "Returns true if data is considered nominally valid" 3 | def valid?(data) 4 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex5-protocol/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex5-protocol/test/valid_test.exs: -------------------------------------------------------------------------------- 1 | defmodule ValidTest do 2 | use ExUnit.Case 3 | doctest Valid 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex6-protocol/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex6-protocol/lib/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defimpl Valid, for: Planemo do 6 | def valid?(p) do 7 | p.gravity >= 0 && p.diameter >= 0 && 8 | p.distance_from_sun >= 0 9 | end 10 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex6-protocol/lib/tower.ex: -------------------------------------------------------------------------------- 1 | defmodule Tower do 2 | defstruct location: "", height: 20, planemo: :earth, name: "" 3 | end 4 | 5 | defimpl Valid, for: Tower do 6 | def valid?(%Tower{height: h, planemo: p}) do 7 | h >= 0 && p != nil 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex6-protocol/lib/valid.ex: -------------------------------------------------------------------------------- 1 | defprotocol Valid do 2 | @doc "Returns true if data is considered nominally valid" 3 | def valid?(data) 4 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex6-protocol/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex6-protocol/test/valid_test.exs: -------------------------------------------------------------------------------- 1 | defmodule ValidTest do 2 | use ExUnit.Case 3 | doctest Valid 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex7-inspect/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex7-inspect/lib/planemo.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | defstruct name: :nil, gravity: 0, diameter: 0, distance_from_sun: 0 3 | end 4 | 5 | defimpl Valid, for: Planemo do 6 | def valid?(p) do 7 | p.gravity >= 0 && p.diameter >= 0 && 8 | p.distance_from_sun >= 0 9 | end 10 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex7-inspect/lib/valid.ex: -------------------------------------------------------------------------------- 1 | defprotocol Valid do 2 | @doc "Returns true if data is considered nominally valid" 3 | def valid?(data) 4 | end -------------------------------------------------------------------------------- /2nd-edition/ch07/ex7-inspect/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch07/ex7-inspect/test/valid_test.exs: -------------------------------------------------------------------------------- 1 | defmodule ValidTest do 2 | use ExUnit.Case 3 | doctest Valid 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch08/ex1-hof/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch08/ex1-hof/README.md: -------------------------------------------------------------------------------- 1 | # Hof 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `hof` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:hof, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `hof` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:hof]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch08/ex1-hof/lib/hof.ex: -------------------------------------------------------------------------------- 1 | defmodule Hof do 2 | def tripler(value, function) do 3 | 3 * function.(value) 4 | end 5 | end 6 | 7 | -------------------------------------------------------------------------------- /2nd-edition/ch08/ex1-hof/test/hof_test.exs: -------------------------------------------------------------------------------- 1 | defmodule HofTest do 2 | use ExUnit.Case 3 | doctest Hof 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch08/ex1-hof/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex1-simple/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex1-simple/lib/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report do 3 | receive do 4 | msg -> IO.puts("Received #{msg}") 5 | end 6 | end 7 | end 8 | 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex1-simple/test/bounce_test.exs: -------------------------------------------------------------------------------- 1 | defmodule BounceTest do 2 | use ExUnit.Case 3 | doctest Bounce 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex1-simple/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex10-resilient/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex10-resilient/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex10-resilient/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex2-recursion/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex2-recursion/lib/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report do 3 | receive do 4 | msg -> IO.puts("Received #{msg}") 5 | report() 6 | end 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex2-recursion/test/bounce_test.exs: -------------------------------------------------------------------------------- 1 | defmodule BounceTest do 2 | use ExUnit.Case 3 | doctest Bounce 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex2-recursion/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex3-counter/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex3-counter/lib/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report(count) do 3 | receive do 4 | msg -> IO.puts("Received #{count}: #{msg}") 5 | report(count + 1) 6 | end 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex3-counter/test/bounce_test.exs: -------------------------------------------------------------------------------- 1 | defmodule BounceTest do 2 | use ExUnit.Case 3 | doctest Bounce 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex3-counter/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex4-state/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex4-state/lib/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report(count) do 3 | new_count = receive do 4 | msg -> IO.puts("Received #{count}: #{msg}") 5 | count + 1 6 | end 7 | report(new_count) 8 | end 9 | end 10 | 11 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex4-state/test/bounce_test.exs: -------------------------------------------------------------------------------- 1 | defmodule BounceTest do 2 | use ExUnit.Case 3 | doctest Bounce 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex4-state/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex5-division/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex5-division/lib/bounce.ex: -------------------------------------------------------------------------------- 1 | defmodule Bounce do 2 | def report do 3 | receive do 4 | x -> IO.puts("Divided to #{x / 2}") 5 | report() 6 | end 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex5-division/test/bounce_test.exs: -------------------------------------------------------------------------------- 1 | defmodule BounceTest do 2 | use ExUnit.Case 3 | doctest Bounce 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex5-division/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex6-talking/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex6-talking/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex6-talking/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex6-talking/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex7-talkingProcs/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex7-talkingProcs/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex7-talkingProcs/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex8-linking/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex8-linking/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex8-linking/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex9-trapping/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex9-trapping/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/ex9-trapping/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch09/testor/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch09/testor/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch09/testor/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1-tryCatch/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1-tryCatch/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1-tryCatch/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.71 7 | end 8 | try do 9 | :math.sqrt(2 * gravity * distance) 10 | rescue 11 | error -> error 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1-tryCatch/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1-tryCatch/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1a-tryCatch/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1a-tryCatch/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | try do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | rescue 11 | error -> error 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1a-tryCatch/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1a-tryCatch/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1b-tryCatch/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1b-tryCatch/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | try do 4 | gravity = case planemo do 5 | :earth -> 9.8 6 | :moon -> 1.6 7 | :mars -> 3.71 8 | end 9 | :math.sqrt(2 * gravity * distance) 10 | rescue 11 | ArithmeticError -> {:error, "Distance must be non-negative"} 12 | CaseClauseError -> {:error, "Unknown planemo #{planemo}"} 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1b-tryCatch/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex1b-tryCatch/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex2-debug/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex2-debug/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex2-debug/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex3-debug/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex3-debug/README.md: -------------------------------------------------------------------------------- 1 | # Fact 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `fact` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:fact, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `fact` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:fact]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex3-debug/lib/fact.ex: -------------------------------------------------------------------------------- 1 | defmodule Fact do 2 | 3 | def factorial(n) do 4 | factorial(1, n, 1) 5 | end 6 | 7 | defp factorial(current, n, result) when current <= n do 8 | new_result = result * current 9 | IO.puts("#{current} yields #{new_result}.") 10 | factorial(current + 1, n, new_result) 11 | end 12 | 13 | defp factorial(_current, _n, result) do 14 | IO.puts("finished!") 15 | result 16 | end 17 | 18 | end -------------------------------------------------------------------------------- /2nd-edition/ch10/ex3-debug/test/fact_test.exs: -------------------------------------------------------------------------------- 1 | defmodule FactTest do 2 | use ExUnit.Case 3 | doctest Fact 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch10/ex3-debug/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/dia_test/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/dia_test/lib/dia_test.ex: -------------------------------------------------------------------------------- 1 | defmodule DiaTest do 2 | 3 | @spec manipulate({atom(), number()}) :: number() 4 | def manipulate({op, n}) do 5 | if op == :add do 6 | n + 1 7 | else 8 | n - 1 9 | end 10 | end 11 | 12 | def calculate() do 13 | x = manipulate({:add, 3}) 14 | y = manipulate({4, :sub}) 15 | IO.puts("Values #{x}, #{y}.") 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/dia_test/test/dia_test_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DiaTestTest do 2 | use ExUnit.Case 3 | doctest DiaTest 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch11/dia_test/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex1-guards/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex1-guards/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex1-guards/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex1-guards/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex2-specs/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex2-specs/test/specs_test.exs: -------------------------------------------------------------------------------- 1 | defmodule SpecsTest do 2 | use ExUnit.Case 3 | doctest Specs 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex2-specs/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex3-specs/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex3-specs/test/new_type_test.exs: -------------------------------------------------------------------------------- 1 | defmodule NewTypeTest do 2 | use ExUnit.Case 3 | doctest NewType 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex3-specs/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4-testing/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4-testing/lib/drop_bad.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.41 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | 12 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4-testing/lib/drop_good.ee: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.71 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | 12 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4-testing/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case, async: true 3 | 4 | test "Zero distance gives zero velocity" do 5 | assert Drop.fall_velocity(:earth,0) == 0 6 | end 7 | 8 | test "Mars calculation correct" do 9 | assert Drop.fall_velocity(:mars, 10) == :math.sqrt(2 * 3.71 * 10) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4-testing/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/README.md: -------------------------------------------------------------------------------- 1 | # Drop 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `drop` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:drop, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `drop` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:drop]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.71 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/test/drop2_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Drop2Test do 2 | use ExUnit.Case 3 | 4 | test "Earth calculation correct" do 5 | calculated = Drop.fall_velocity(:earth, 1) 6 | assert_in_delta calculated, 4.4, 0.05, 7 | "Result of #{calculated} is not within 0.05 of 4.4" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/test/drop3_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Drop3Test do 2 | use ExUnit.Case 3 | 4 | test "Earth calculation correct" do 5 | calculated = Drop.fall_velocity(:earth, 1) 6 | assert_in_delta calculated, 4.4, 0.0001, 7 | "Result of #{calculated} is not within 0.0001 of 4.4" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/test/drop4_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Drop4Test do 2 | use ExUnit.Case 3 | 4 | test "Unknown planemo causes error" do 5 | assert_raise CaseClauseError, fn -> 6 | Drop.fall_velocity(:planetX, 10) 7 | end 8 | end 9 | 10 | test "Negative distance causes error" do 11 | assert_raise ArithmeticError, fn -> 12 | Drop.fall_velocity(:earth, -10) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | 4 | test "Zero distance gives zero velocity" do 5 | assert Drop.fall_velocity(:earth,0) == 0 6 | end 7 | 8 | test "Mars calculation correct" do 9 | assert Drop.fall_velocity(:mars, 10) == :math.sqrt(2 * 3.71 * 10) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex4a-testing/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex5-setup/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex5-setup/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | def fall_velocity(planemo, distance) do 3 | gravity = case planemo do 4 | :earth -> 9.8 5 | :moon -> 1.6 6 | :mars -> 3.71 7 | end 8 | :math.sqrt(2 * gravity * distance) 9 | end 10 | end 11 | 12 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex5-setup/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex6-doctest/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex6-doctest/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case, async: false 3 | doctest Drop 4 | end 5 | -------------------------------------------------------------------------------- /2nd-edition/ch11/ex6-doctest/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/zorko/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch11/zorko/README.md: -------------------------------------------------------------------------------- 1 | # Zorko 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: 8 | 9 | 1. Add `zorko` to your list of dependencies in `mix.exs`: 10 | 11 | ```elixir 12 | def deps do 13 | [{:zorko, "~> 0.1.0"}] 14 | end 15 | ``` 16 | 17 | 2. Ensure `zorko` is started before your application: 18 | 19 | ```elixir 20 | def application do 21 | [applications: [:zorko]] 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /2nd-edition/ch11/zorko/lib/zorko.ex: -------------------------------------------------------------------------------- 1 | defmodule Zorko do 2 | end 3 | -------------------------------------------------------------------------------- /2nd-edition/ch11/zorko/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch11/zorko/test/zorko_test.exs: -------------------------------------------------------------------------------- 1 | defmodule ZorkoTest do 2 | use ExUnit.Case 3 | doctest Zorko 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex1-records/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex1-records/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex1-records/test/records_test.exs: -------------------------------------------------------------------------------- 1 | defmodule RecordsTest do 2 | use ExUnit.Case 3 | doctest Records 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex1-records/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex2-records/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex2-records/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex2-records/test/record_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule RecordDropTest do 2 | use ExUnit.Case 3 | doctest RecordDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex2-records/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex3-records/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex3-records/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex3-records/test/record_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule RecordDropTest do 2 | use ExUnit.Case 3 | doctest RecordDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex3-records/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex4-records/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex4-records/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex4-records/test/record_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule RecordDropTest do 2 | use ExUnit.Case 3 | doctest RecordDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex4-records/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex5-ets/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex5-ets/lib/planemo_storage.ex: -------------------------------------------------------------------------------- 1 | defmodule PlanemoStorage do 2 | require Planemo 3 | 4 | def setup do 5 | planemo_table = :ets.new(:planemos,[:named_table, 6 | {:keypos, Planemo.planemo(:name) + 1}]) 7 | :ets.info planemo_table 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex5-ets/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex5-ets/test/planemo_storage_test.exs: -------------------------------------------------------------------------------- 1 | defmodule PlanemoStorageTest do 2 | use ExUnit.Case 3 | doctest PlanemoStorage 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex5-ets/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex6-ets/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex6-ets/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex6-ets/test/planemo_storage_test.exs: -------------------------------------------------------------------------------- 1 | defmodule PlanemoStorageTest do 2 | use ExUnit.Case 3 | doctest PlanemoStorage 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex6-ets/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex7-ets-calculator/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex7-ets-calculator/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex7-ets-calculator/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex7-ets-calculator/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex8-mnesia/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex8-mnesia/Mnesia.nonode@nohost/DECISION_TAB.LOG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch12/ex8-mnesia/Mnesia.nonode@nohost/DECISION_TAB.LOG -------------------------------------------------------------------------------- /2nd-edition/ch12/ex8-mnesia/Mnesia.nonode@nohost/LATEST.LOG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch12/ex8-mnesia/Mnesia.nonode@nohost/LATEST.LOG -------------------------------------------------------------------------------- /2nd-edition/ch12/ex8-mnesia/Mnesia.nonode@nohost/schema.DAT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch12/ex8-mnesia/Mnesia.nonode@nohost/schema.DAT -------------------------------------------------------------------------------- /2nd-edition/ch12/ex8-mnesia/lib/records.ex: -------------------------------------------------------------------------------- 1 | defmodule Planemo do 2 | require Record 3 | Record.defrecord :planemo, [name: :nil, gravity: 0, diameter: 0, 4 | distance_from_sun: 0] 5 | end 6 | 7 | defmodule Tower do 8 | require Record 9 | Record.defrecord :tower, Tower, 10 | [location: "", height: 20, planemo: :earth, name: ""] 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex8-mnesia/test/mph_drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MphDropTest do 2 | use ExUnit.Case 3 | doctest MphDrop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch12/ex8-mnesia/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch12/tower_definitions.txt: -------------------------------------------------------------------------------- 1 | require Tower 2 | tower1 = Tower.tower() 3 | tower2 = Tower.tower(location: "Grand Canyon") 4 | tower3 = Tower.tower(location: "NYC", height: 241, name: "Woolworth Building") 5 | tower4 = Tower.tower location: "Rupes Altat 241", height: 500, planemo: :moon, name: "Piccolini View" 6 | tower5 = Tower.tower planemo: :mars, height: 500, name: "Daga Vallis", location: "Valles Marineris" 7 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex1-drop/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex1-drop/test/drop_server_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropServerTest do 2 | use ExUnit.Case 3 | doctest DropServer 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex1-drop/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex2-drop-sup/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex2-drop-sup/lib/drop_sup.ex: -------------------------------------------------------------------------------- 1 | defmodule DropSup do 2 | use Supervisor 3 | 4 | # convenience method for startup 5 | 6 | def start_link do 7 | Supervisor.start_link(__MODULE__, [], [{:name, __MODULE__}]) 8 | end 9 | 10 | # supervisor callback 11 | 12 | def init([]) do 13 | child = [worker(DropServer, [], [])] 14 | supervise(child, [{:strategy, :one_for_one}, {:max_restarts, 1}, 15 | {:max_seconds, 5}]) 16 | end 17 | 18 | # Internal functions (none here) 19 | end 20 | 21 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex2-drop-sup/test/drop_sup_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropSupTest do 2 | use ExUnit.Case 3 | doctest DropSup 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex2-drop-sup/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex3-drop-app/drop_app/lib/drop_app.ex: -------------------------------------------------------------------------------- 1 | defmodule DropApp do 2 | use Application 3 | 4 | def start(_type, _args) do 5 | IO.puts("Starting the app...") # show that app si really starting. 6 | DropSup.start_link() 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex3-drop-app/drop_app/lib/drop_sup.ex: -------------------------------------------------------------------------------- 1 | defmodule DropSup do 2 | use Supervisor 3 | 4 | # convenience method for startup 5 | 6 | def start_link do 7 | Supervisor.start_link(__MODULE__, [], [{:name, __MODULE__}]) 8 | end 9 | 10 | # supervisor callback 11 | 12 | def init([]) do 13 | child = [worker(DropServer, [], [])] 14 | supervise(child, [{:strategy, :one_for_one}, {:max_restarts, 1}, 15 | {:max_seconds, 5}]) 16 | end 17 | 18 | # Internal functions (none here) 19 | end 20 | 21 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex3-drop-app/drop_app/test/drop_app_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropAppTest do 2 | use ExUnit.Case 3 | doctest DropApp 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch13/ex3-drop-app/drop_app/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex1-difference/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex1-difference/lib/difference.ex: -------------------------------------------------------------------------------- 1 | defmodule Difference do 2 | 3 | defmacro m_test(x) do 4 | IO.puts("#{inspect(x)}") 5 | x 6 | end 7 | 8 | def f_test(x) do 9 | IO.puts("#{inspect(x)}") 10 | x 11 | end 12 | end 13 | 14 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex1-difference/test/difference_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DifferenceTest do 2 | use ExUnit.Case 3 | doctest Difference 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex1-difference/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex2-double/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex2-double/lib/bad_double.ex: -------------------------------------------------------------------------------- 1 | defmodule BadDouble do 2 | 3 | defmacro double(x) do 4 | quote do: 2 * x 5 | end 6 | 7 | end 8 | 9 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex2-double/lib/double.ex: -------------------------------------------------------------------------------- 1 | defmodule Double do 2 | 3 | defmacro double x do 4 | {:*, [], [2, x]} 5 | end 6 | end 7 | 8 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex2-double/test/double_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DoubleTest do 2 | use ExUnit.Case 3 | doctest Double 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex2-double/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex3-double/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex3-double/lib/double.ex: -------------------------------------------------------------------------------- 1 | defmodule Double do 2 | 3 | defmacro double(x) do 4 | quote do 5 | 2 * unquote(x) 6 | end 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex3-double/test/double_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DoubleTest do 2 | use ExUnit.Case 3 | doctest Double 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex3-double/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex4-unless/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex4-unless/lib/logic.ex: -------------------------------------------------------------------------------- 1 | defmodule Logic do 2 | 3 | defmacro unless(condition, options) do 4 | quote do 5 | if(!unquote(condition), unquote(options)) 6 | end 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex4-unless/test/logic_test.exs: -------------------------------------------------------------------------------- 1 | defmodule LogicTest do 2 | use ExUnit.Case 3 | doctest Logic 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex4-unless/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex5-programmatic/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex5-programmatic/lib/function_maker.ex: -------------------------------------------------------------------------------- 1 | defmodule FunctionMaker do 2 | defmacro create_multiplier(function_name, factor) do 3 | quote do 4 | def unquote(function_name)(value) do 5 | unquote(factor) * value 6 | end 7 | end 8 | end 9 | end 10 | 11 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex5-programmatic/lib/multiply.ex: -------------------------------------------------------------------------------- 1 | defmodule Multiply do 2 | require FunctionMaker 3 | 4 | FunctionMaker.create_multiplier(:double, 2) 5 | FunctionMaker.create_multiplier(:triple, 3) 6 | 7 | def example do 8 | x = triple(12) 9 | IO.puts("Twelve times 3 is #{x}") 10 | end 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex5-programmatic/test/multiply_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MultiplyTest do 2 | use ExUnit.Case 3 | doctest Multiply 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex5-programmatic/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex6-multidrop/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex6-multidrop/lib/drop.ex: -------------------------------------------------------------------------------- 1 | defmodule Drop do 2 | require FunctionMaker 3 | 4 | FunctionMaker.create_functions([{:mercury, 3.7}, {:venus, 8.9}, 5 | {:earth, 9.8}, {:moon, 1.6}, {:mars, 3.7}, 6 | {:jupiter, 23.1}, {:saturn, 9.0}, {:uranus, 8.7}, 7 | {:neptune, 11.0}, {:pluto, 0.6}]) 8 | 9 | end 10 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex6-multidrop/lib/function_maker.ex: -------------------------------------------------------------------------------- 1 | defmodule FunctionMaker do 2 | defmacro create_functions(planemo_list) do 3 | Enum.map planemo_list, fn{name, gravity} -> 4 | quote do 5 | def unquote(:"#{name}_drop")(distance) do 6 | :math.sqrt(2 * unquote(gravity) * distance) 7 | end 8 | end 9 | end 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex6-multidrop/test/drop_test.exs: -------------------------------------------------------------------------------- 1 | defmodule DropTest do 2 | use ExUnit.Case 3 | doctest Drop 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch14/ex6-multidrop/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/.gitignore: -------------------------------------------------------------------------------- 1 | # App artifacts 2 | /_build 3 | /db 4 | /deps 5 | /*.ez 6 | 7 | # Generated on crash by the VM 8 | erl_crash.dump 9 | 10 | # The config/prod.secret.exs file by default contains sensitive 11 | # data and you should not commit it into version control. 12 | # 13 | # Alternatively, you may comment the line below and commit the 14 | # secrets file as long as you replace its contents by environment 15 | # variables. 16 | /config/prod.secret.exs 17 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/config/test.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | # We don't run a server during test. If one is required, 4 | # you can enable the server option below. 5 | config :fall, Fall.Endpoint, 6 | http: [port: 4001], 7 | server: false 8 | 9 | # Print only warnings and errors during test 10 | config :logger, level: :warn 11 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/priv/gettext/en/LC_MESSAGES/errors.po: -------------------------------------------------------------------------------- 1 | ## `msgid`s in this file come from POT (.pot) files. 2 | ## 3 | ## Do not add, change, or remove `msgid`s manually here as 4 | ## they're tied to the ones in the corresponding POT file 5 | ## (with the same domain). 6 | ## 7 | ## Use `mix gettext.extract --merge` or `mix gettext.merge` 8 | ## to merge POT files into PO files. 9 | msgid "" 10 | msgstr "" 11 | "Language: en\n" 12 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/priv/gettext/errors.pot: -------------------------------------------------------------------------------- 1 | ## This file is a PO Template file. 2 | ## 3 | ## `msgid`s here are often extracted from source code. 4 | ## Add new translations manually only if they're dynamic 5 | ## translations that can't be statically extracted. 6 | ## 7 | ## Run `mix gettext.extract` to bring this file up to 8 | ## date. Leave `msgstr`s empty as changing them here as no 9 | ## effect: edit them in PO (`.po`) files instead. 10 | 11 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/priv/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch15/fall/priv/static/favicon.ico -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/priv/static/images/phoenix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonstl/introducing-elixir/2d418cb4caeca807f6cd1f33f0fb3df3d38d2522/2nd-edition/ch15/fall/priv/static/images/phoenix.png -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/priv/static/js/app.js: -------------------------------------------------------------------------------- 1 | // for phoenix_html support, including form and button helpers 2 | // copy the following scripts into your javascript bundle: 3 | // * https://raw.githubusercontent.com/phoenixframework/phoenix_html/v2.3.0/priv/static/phoenix_html.js -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/priv/static/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/test/controllers/page_controller_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Fall.PageControllerTest do 2 | use Fall.ConnCase 3 | 4 | test "GET /", %{conn: conn} do 5 | conn = get conn, "/" 6 | assert html_response(conn, 200) =~ "Welcome to Phoenix!" 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start 2 | 3 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/test/views/layout_view_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Fall.LayoutViewTest do 2 | use Fall.ConnCase, async: true 3 | end 4 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/test/views/page_view_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Fall.PageViewTest do 2 | use Fall.ConnCase, async: true 3 | end 4 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/web/controllers/page_controller.ex: -------------------------------------------------------------------------------- 1 | defmodule Fall.PageController do 2 | use Fall.Web, :controller 3 | 4 | def index(conn, _params) do 5 | render conn, "index.html" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/web/templates/fall/faller.html.eex: -------------------------------------------------------------------------------- 1 |

Speed at impact was <%= @speed %> m/s.

2 | 3 |

Fall again?

4 | 5 | <%= form_for @conn, fall_path(@conn, :faller), [as: :calculation], 6 | fn f-> %> 7 | <%= select f, :planemo, @choices %> 8 | <%= text_input f, :distance %> 9 | <%= submit "Calculate" %> 10 | <% end %> 11 | 12 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/web/templates/fall/welcome.html.eex: -------------------------------------------------------------------------------- 1 |

Falling starts now!

2 | 3 | <%= form_for @conn, fall_path(@conn, :faller), [as: :calculation], 4 | fn f-> %> 5 | <%= select f, :planemo, @choices %> 6 | <%= text_input f, :distance %> 7 | <%= submit "Calculate" %> 8 | <% end %> 9 | 10 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/web/views/error_view.ex: -------------------------------------------------------------------------------- 1 | defmodule Fall.ErrorView do 2 | use Fall.Web, :view 3 | 4 | def render("404.html", _assigns) do 5 | "Page not found" 6 | end 7 | 8 | def render("500.html", _assigns) do 9 | "Internal server error" 10 | end 11 | 12 | # In case no render clause matches or no 13 | # template is found, let's render it as 500 14 | def template_not_found(_template, assigns) do 15 | render "500.html", assigns 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/web/views/fall.ex: -------------------------------------------------------------------------------- 1 | defmodule Fall.FallView do 2 | use Fall.Web, :view 3 | end 4 | 5 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/web/views/layout_view.ex: -------------------------------------------------------------------------------- 1 | defmodule Fall.LayoutView do 2 | use Fall.Web, :view 3 | end 4 | -------------------------------------------------------------------------------- /2nd-edition/ch15/fall/web/views/page_view.ex: -------------------------------------------------------------------------------- 1 | defmodule Fall.PageView do 2 | use Fall.Web, :view 3 | end 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | introducing-elixir 2 | ================== 3 | 4 | Example code from Introducing Elixir. 5 | --------------------------------------------------------------------------------