Sunday, August 12, 2012

Seven Languages in Seven Weeks : Erlang Day 2

I'm reading Seven Languages in Seven weeks. It's a great book to discover different kind of languages. I went through Ruby, Io, Prolog, Scala and Erlang. So far, Prolog has been the most puzzling of all. For example, the map coloring sample. The author shows how to colorize several states of the United States, without assigning the same color to adjacent states. I finally got the point after noticing that all states names begin with an uppercase letter. Aaaaaaahhhh ! Colors will be assigned to each state (a state is just a variable), and prolog will go through all combinations of colors, returning true only if all combinations in the coloring query return true. Although it was obvious in the food example, food_type(What, meat), for some reason it was not so obvious in the map coloring example...

On the contrary, I'm very interested in Erlang. One of the exercises is to tell in which state a Tic-Tac-Toe board is. Did X win ? Did O win ? No winner yet ? No more moves ? This is the solution I came up with, after several refactoring passes. I like the way we can interact with lists and tuples.


winner(Board) ->
 [A,B,C,D,E,F,G,H,I] = Board,

% Filter the board for winning combinations
Result = lists:filter(
  fun({X,Y,Z}) -> (X=:=Y) and (X=:=Z) end,

% Checking the winner
case Result of
 % There is a winner
 [First|_] -> {Winner,_,_} = First, Winner;
 % No winner
 _ ->
 % Is there any slot left to play ?
 case lists:any(fun(X) -> X=:="" end, Board) of
  true -> "no winner";
  false -> "cat"

Friday, August 3, 2012

London Olympics judo and Japanese television

(This one is in Japanese. The London Olympic 100kg+ Judo men final was not shown on Japanese television. I have a few words to say about that)


あの時間帯に、3つのチャネルがロンドンオリンピックを放送したいた。NHK総合、NHK BS1ともうひとつ。3つともアーチェリー。どういうこと?


  • 変なプライドを捨てましょう。他の国を見て。銅メダルを取るだけで大喜び、大感動。日本選手は?金でないかぎり、泣く。実力がないのに金ばかりにこだわるのは、相応しくない。大会が始まる前に他の選手よりプレッシャーが大きくなるだけ。逆効果ではないでしょうか?
  • お家芸。大辞泉より:最も得意とする事柄。「柔道は日本の―」。それはないでしょう。昔はね。最も得意だったのかもしれないが、今はどうでしょうか?柔道に対して「お家芸」というのは、廃語にすべき。
  • テレビ放送。またプライドの問題でしょうが、日本人選手が出ないと放送しないという考え方は、やめましょう。決勝は決勝なので、遅くまで見ているのに、放送しないなんて。柔道の結果は屈辱か?日本のテレビ放送の方が屈辱的。柔道をそんなに好きだったら、そんなに期待していたら、そんなに伝統だと思っていたら、ちゃんと最後まで放送してね。
以上、素朴な柔道改革提案書。 (アーチェリーに恨みがございません)

Songs bought on iTunes abruptly stop playing

I bought two albums on iTunes last weekend. All my songs stopped after about one minute of play. I searched for similar problems on the net, and it appears that a lot of people are annoyed with this too. I found different recovery methods, but none of them worked for me. The most common recovery method was to remove the files and redownload them from iTunes. I removed the files, went to my purchase history on iTunes and redownloaded the whole album.

Unfortunately, the songs were still cut at approximately the same place...
What solved my problem was not to redownload the whole album at once, but to redownload each song one by one. Yes, it's annoying, but at least the songs were finally playing properly up to the end. Let's hope that iTunes is going to be fixed soon.