Tuesday, September 15, 2009

Finished my 'hello world' in Erlang.

All it took was 3 days of catching up on Erlang programming and 17 lines of code and tadaaa.. I have the little twitter search app I wanted to make.

Erlang is really nice. It was fairly easy to write the little twitter app, with a little help from a JSON lib I found. (mochijson2 also used in CouchDB, so I hear)
I'm going to miss pattern matching when I code in some other language. It makes things so much easier and clearer.

I haven't had this much fun programming since I made my last web-app in Lisp.

Next up: re-write that same web-app in Erlang.


The little app probably has lots of room for improvements, refactoring, cleaning up and is probably not the best Erlang style, but it works! :D
I'm very impressed with how easy this was to write.

I called it 'twitt' so the filename would be 'twitt.erl'..


-module(twitt).
-compile(export_all).

get_search(Search) ->
application:start(inets),
{ok,{_,_,Json}} =
http:request("http://search.twitter.com/search.json?q="++Search),
show_tweets(make_tweetlist(Json)).

get_entries_from_json({struct,[Results|_]}) ->
Results;
get_entries_from_json(_) ->
fail.

make_tweetlist(Json) ->
element(2,get_entries_from_json(mochijson2:decode(Json))).

print_tweet({struct,[{_,_Image},{_,_Created},
{_,From},{_,_ToUId},{_,Text},{_,_Id},{_,_FromUId},{_,_IsoLang},{_,_Source}]}) ->
io:format("From: ~p~n-- ~p~n",[binary_to_list(From),binary_to_list(Text)]);
print_tweet(_) -> fail.

show_tweets(TweetList) ->
[ print_tweet(X) || X <- TweetList ].

Thursday, September 10, 2009

No more headaches.

I'm giving up on Haskell.
It's too hard. I just want to write applications that do stuff. Not theorize about how they work and proving whether they work and all that.
Not a bad word about it otherwise though. It's a great language to read, because once you know the syntax, it's actually very easy to read.

It was a good eye-opener for me. but I'm not convinced I need something more practical.

Sticking with functional programming languages though, I'm now going to give Erlang a try. Wish me luck!

(this is turning out to be the quest for the holy gr..programming language. It doesn't exist, but I'm going to look for it anyway! :p)