Created
January 12, 2012 14:38
-
-
Save inoshiro/1600884 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7つの言語 7つの世界 のセルフスタディで書いたコード。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(day01_count). | |
-export([count_words/1]). | |
-export([count_ten/0]). | |
count_words(Str) -> | |
count_words(Str, 1). | |
count_words([], Num) -> | |
Num; | |
count_words(Str, Num) -> | |
[Head|Tail] = Str, | |
case Head of | |
32 -> count_words(Tail, Num + 1); | |
_ -> count_words(Tail, Num) | |
end. | |
count_ten() -> | |
count_ten(1). | |
count_ten(10) -> | |
10; | |
count_ten(Num) -> | |
io:write(Num), | |
io:nl(), | |
count_ten(Num + 1). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(day01_errormsg). | |
-export([get_message/1]). | |
get_message(success) -> io:put_chars("success"), io:nl(); | |
get_message({error, Message}) -> io:put_chars("error: " ++ Message), io:nl(). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1> Calc = fun({Item, Quantity, Price}) -> {Item, Quantity * Price} end. | |
#Fun<erl_eval.6.80247286> | |
2> Calc({"MacBookAir", 110000, 100}). | |
{"MacBookAir",11000000} | |
3> Items = [{"MacBookAir", 110000, 5}, {"iPhone", 50000, 10}, {"iPad", 70000, 3}]. | |
[{"MacBookAir",110000,5}, | |
{"iPhone",50000,10}, | |
{"iPad",70000,3}] | |
4> [Calc(Item) || Item <- Items]. | |
[{"MacBookAir",550000},{"iPhone",500000},{"iPad",210000}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(day02_listutil). | |
-export([get_key/2]). | |
get_key(Items, Key) -> | |
Check = fun({K,_}) -> K == Key end, | |
[{_, V}] = lists:filter(Check, Items), | |
V. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment