Wednesday, June 15, 2011

Maximum Segment Sum



This is something I always forget. During the summer, I should be learning and practicing how to deduce this linear-time algorithm in a formal way.

The programming languages course has ended today. I've learned something, but didn't practice enough. Those tools for reasoning imperative programs look well in some trivial examples, but I wonder how they can be useful in some larger ones. What I want to know the most is whether these methods can help me figure out an efficient algorithm for certain program. Anyway, I feel more comfortable in programming languages class than algorithms class. The former class is of course a lot easier, but the stuff in it really helps me to understand something, not just memorizing some details in an hard-to-reason-with imperative algorithm.

Computer programming, to me, is not a tool for shipping some valuable things to customers. Developing software is not what I'd be doing well. Programming is rather a thinking aid to me. The better the language interact with your thoughts, the better picture you can get. Monads, for example, exist (in programming) not for some abstract beauty, but really for capturing and shaping some realistic things and processes. After taking so many engineering classes, no single one other than programming languages class really shed some light on the context of discovery. All we see are just results. They are great, significant and beautiful. So what? How can we discover or create something like them, not something that is lame and trivial?

Maybe it's too hard to answer. Too philosophical. Also, asking questions like these just made myself look like a lazy and careless student. Well, I surely won't stop questioning, but I'll make a promise. I promise that I will try harder, harder and harder.

Saturday, May 28, 2011

Some Emacs Stuff

DarkRoom模式感覺非常酷,也非常好用。

該來學學org-mode了。

Tuesday, April 26, 2011

Strict function

Operationally, a strict function is one which always evaluates its argument, a non-strict function is one which may not evaluate some of its arguments. Functions having more than one parameter may be strict or non-strict in each parameter independently, as well as jointly strict in several parameters simultaneously.
http://en.wikipedia.org/wiki/Strict_function

"f x = f 42" seems to be strict!

一些連結

Haskell
數學

Friday, August 20, 2010

Perl的__DATA__

在簡單的Perl Script中,常常會在程式碼的結尾加上一列__DATA__,然後在底下放入程式所需的資料。

#!/usr/bin/perl
use 5.010;

while (my $name = <data>) {
chomp $name;
say "Hello, $name!";
}

__DATA__
Peter
Jack
Obama

問題來了,如果DATA的內容需要讀取不只一遍的時候,你沒辦法直接用seek回到DATA的最前端。這是因為DATA其實是整個script檔案的filehandle,當你第一次使用它的時候,其offset其實設在__DATA__這列之後。所以若需要讀取DATA兩遍以上,需要先以

my $pos = tell DATA;

紀錄DATA一開始的position,然後在讀取第二遍之前,以

seek DATA, $pos, 0;

回到這個filehandle原先的位置。

Tuesday, August 3, 2010

Textbooks

Every basic thing you should know, every kind of skills with which you should be equipped...

Young kid, they are all in books.

Go ahead. Read 'em all.