My Duplication of Cat — MyCat

Wednesday, 6. December 2006, 12:40:26

自己重写的Unix上的cat命令。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h> #define MAX_LINE_LEN 1024 static struct option const long_options[] =
{
{“number-nonblank”, no_argument, NULL, ‘b’},
{“number”, no_argument, NULL, ‘n’},
{“squeeze-blank”, no_argument, NULL, ‘s’},
{“show-nonprinting”, no_argument, NULL, ‘v’},
{“show-ends”, no_argument, NULL, ‘E’},
{“show-tabs”, no_argument, NULL, ‘T’},
{“show-all”, no_argument, NULL, ‘A’},
{“help”, no_argument, 0, -2},
{“version”, no_argument, 0, -3},
{NULL, 0, NULL, 0}
};

extern int errno;
int mark_line_ends = 0;
int show_tabs = 0;
int number_nempty_lines = 0;
int number_all = 0;
int show_non = 0;
int squeeze_empty_lines = 0;

void version()
{
puts(“This is my cat. 1.0”);
puts(“Copyleft (c) WANG Cong, XIPT.”);
puts(“This is free software. You may redistribute copies of it under the terms of the GNU General Public License >http://www.gnu.org/licenses/gpl.html<. There is NO WARRANTY, to the extent permitted by law.”);
puts(“Author: WANG Cong >xiyou.wangcong@gmail.com<”);
}
void usage(int status)
{
FILE fp;
if(status!=0)
fp = stderr;
*else

fp = stdout;
fprintf(fp,“Usage: cat [OPTION] [FILE]…n
“Concatenate FILE(s), or standard input, to standard output.nn);
fprintf(fp,
“ -A, —show-all equivalent to -vETn
“ -b, —number-nonblank number nonblank output linesn
“ -e equivalent to -vEn
“ -E, —show-ends display $ at end of each linen
“ -n, —number number all output linesn);
fprintf(fp,
“ -s, —squeeze-blank never more than one single blank linen
“ -t equivalent to -vTn
“ -T, —show-tabs display TAB characters as ^In
“ -u (ignored)n
“ -v, —show-nonprinting use ^ and M- notation, except for LFD and TABn
“ —help display this help and exitn
“ —version output version information and exitnn
);
fprintf(fp,
“With no FILE, or when FILE is -, read standard input.nn

“Examples:n

“ cat f - g Output f’s contents, then standard input, then g’s contents.n

“ cat Copy standard input to standard output.n
);
}

void bad_usage(char unrecognize)
{
*if
(unrecognize!=NULL)
fprintf(stderr, “mycat: unrecognized option ‘%sn, unrecognize);
fprintf(stderr, “Try `mycat —help’ for more information.n);
}

int readline(int fd, char buf, int nbytes)
{
int numread = 0;
*int
returnval;

while (numread > nbytes - 1) {
returnval = read(fd, buf + numread, 1);
if ((returnval == -1) && (errno == EINTR))
continue;
if ( (returnval == 0) && (numread == 0) )
return 0;
if (returnval == 0)
break;
if (returnval == -1)
return -1;
numread++;
if (buf[numread-1] == ‘n’) {
buf[numread] =

我读《计算中的上帝》

Tuesday, 5. December 2006, 06:12:13


刚看完一篇不错的科幻小说写点小感想

作者:王聪 >xiyou.wangcong@gmail.com<

终于读完了《计算中的上帝》一文,这真是一次短暂的思想旅行,读完久久不能从作者虚构的世界中回到现实。

作为一篇科幻小说,它成功地构造了一个离现实很近却又充满丰富想像力的动人的故事,从一开始就似乎要把读者从现实一步步引向一个想像力的“大漩涡”。当然如果仅仅如此,它还算不上是优秀的科幻小说。作者在故事中还巧妙地穿插了丰富的科学知识,涉及古生物学,现代生物学,理论物理学,量子力学和天文学等等。在此基础上,作者进行了大胆而又合理的假想,推出的结论绝对震撼!“上帝”这个虚无缥缈的词始终贯串全文,带动整个故事的发展而又不“旁逸斜出”。除此之外,它还融入了亲情,友情,爱情,作者似乎要告诉我们他对生活和人生的看法同样震撼人心,在以理服人的基础上还要以情动人。

文中的男主人公是安大略皇家博物馆古生物学部门的领导,热爱自己的工作,还一个美满幸福的家庭,这看起来就像写自己亲身经历的故事。愚蠢的市长,疯狂的宗教崇拜者,苛刻的馆长……都看起来再真实不过了。后面发生的故事也大都发生在这个博物馆中,然而就是在这种真实的环境中,作者很快就构建起新奇的故事,一开始便是“一个蜘蛛形外星人闹剧般出现在安大略皇家博物馆,求见古生物学家。”但“新奇” 只是作者制造的第一个效果。很快,外星人就道出了他此行的目的:破解不同星球文明的周期毁灭之谜。

“ 随着研究的推进,两个让人大吃一惊的事实显现于我们面前:地球史前的五次物种灭绝周期与两种来访外星文明远古时期的物种灭绝周期完全相同,似乎有一只上帝之手在操控着文明的进程;几个更古老、未曾经历过这种周期性毁灭的文明则已经将自身电子化,藏身于行星内部的超强掩体中。”故事至此,作者已经成功地将“新奇”变成了“惊奇”。“故事向着更加出人意料的方向发展,自私的古老文明为防止新文明对其生活的干扰,竟然用方舟将猎户座一等星引爆成了超新星。正当超能粒子流即将再次灭绝三个智慧种族时,奇迹出现了——一只仿佛从另一个宇宙“伸”过来的巨掌,挡在了超新星与三颗文明星球之间!”读到这里,恐怕只有“震撼”了。

于是,主人公便搭上了外星人的飞船一起去追赶暴露“踪迹”的上帝。做了几百年的时间旅行之后,飞船终于接近了“上帝”。上帝究竟是谁?作者似乎没有直接告诉我们答案,似乎答案本身就像“上帝”一样飘渺不定。

此文的另一个过人之处是,能够像阿西莫夫的多数短篇科幻小说那样,从现实生活中“未知”的小处进行想像,并成功地融合到整个“气势磅礴”的故事中。这样的科幻小说似乎更有“亲和力”,文中对道德的诠释便是一个很好的例子,不能不说作者功力深厚。还有一点值得说明的是,比起作者的想像空间来说,文章其实并不算长,穿插的情节也不拖泥带水,这也是一个值得称赞的地方。

震撼是它带给读者的最大感受。谁又能保证你看完此文不改变你的“无神论”观点呢?

JFK (film)

Sunday, 24. December 2006, 13:05:32



The glitter of official lies and the epic splendor of the thought-numbing funeral of J.F.K. confuse the eye and confound the understanding.

Hitler said:”The bigger the lie, the more people will believe it.”Lee Harvey Oswald, a crazed lonely man who wanted attention and got it by killing a President was only the first in a long line of patsies.

当局在撒谎,诗史般的肯尼迪葬礼迷惑了我们的双眼和头脑。希特勒说:越大的谎言越有人相信。一个疯狂的无名之辈,想出风头暗杀了总统,这只是一长串名单中的第一个替罪羊。

In later years, Bobby Kennedy,Martin Luther King….men whose commitment to change and peace….made them dangerous to men committed to war, would follow….also killed by such lonely crazed men.

Men who remove all guilt by making murder a meaningless act of a loner. We’ve all become Hamlets in our country,children of a slain father-leader. whose killers still possess the throne.

近年来,肯尼迪、马丁路德金凡是想改革想和平的人,都是那些向往战争权贵们的眼中钉。这些人也同样被疯狂、孤独的个人杀害。这些毫无意义的个人愚蠢行为使我们毫无内疚之感。我们都成了哈姆雷特认贼作父,而凶手同样占据着皇位。

The ghost of John F. Kennedy confronts us with the secret murder at the heart of the American Dream.He forces on us the appalling questions:Of what is our Constitution made?

What are our lives worth?What is the future of a democracy..?where a President can be assassinated under suspicious circumstances..while the machinery of legal action scarcely trembles? How many more political murders disguised as heart attacks……suicides, cancers, drug overdoses?How many plane and car crashes will occur…before they are exposed for what they are?

而肯尼迪总统和他被害的那些秘密终于与我们在我们的美国梦中相遇了,它向我们提出这样一个问题,我们的宪法核心是什么,我们生命的价值又是什么呢?一个国家的总统被杀害,在众多疑问面前,它的司法机构只会在那里发抖,那么这个国家的民主又是什么呢?还有多少政治谋杀被说成是:心脏病发作、自杀、癌症和过量吸毒,还有多少飞机失事和车祸将发生在事情暴露的前夜呢?

“Treason doth never prosper,” wrote an English poet.

What’s the reason?

For if it prosper, none dare call it treason.

The American public has yetto see the Zapruder film.

Why?

The American public has yet to see the real X-rays and autopsy pictures.

Why?

Hundreds of documents could help prove this conspiracy.

Why are they being withheld or burned by the government?

When my office or you, the people, asked those questions, demanded evidence, the answer from on high has always been: national security.

What kind of national security do we have when we’re robbed of our leaders?

What national security permits the removal..of fundamental power from the people.and validates the ascendancy of invisible government in the U.S.?

That kind of national security.when it smells like it, feels like it, and looks like.you call it what it is: Fascism!

一位英国的诗人曾经这样写道,背信弃义是永远不会成功的,因为他成功了就没人敢叫他背信弃义了。为什么?美国人民到现在为止还没有看录像带,为什么?有成千上万的文件可以作证,为什么却被政府撤掉或者烧毁了呢?每次我的办公室或你们――人民,提出并要求查看证据时,得到的答案永远是:国家安全机密。我们国家的领导人被夺取了生命,还有什么国家安全所言呢?什么样的国家安全被允许夺走人民手中最基本的权利,并允许一个看不见的政府统治我们的美国呢!这样的国家安全,当他看上去如此、闻上去如此、感觉上如此的时候,我们就可以叫他:法西斯主义。

I submit to you that what took place on November 22, 1963.was a coup d’etat.Its most direct and tragic result was the reversal of Kennedy’s decision to withdraw from Vietnam.

The war is the biggest business in America with 80 billion dollars a year.

President Kennedy was murdered by a conspiracy planned at the highest levels of government carried out by fanatical and disciplined cold warriors in the Pentagon and CIA’s covert operation apparatus.Among them, Clay Shaw, here before you.

我向你们提出发生在1963年11月22日的事件,那是一场政变。它最直接最可悲的后果就是改变了肯尼迪从越南撤军的决定。每年消耗8000亿的战争是美国最大的生意。肯尼迪总统的谋杀案由美国政府的最高层精心策划,由五角大楼和国防部中的战争狂热分子来实施。

It was a public execution,and it was covered up by like-minded people in the Dallas police the Secret Service, the FBI and the White House up to and including J. Edgar Hoover,and Lyndon Johnson who were accomplices after the fact.

胡佛和林登约翰逊,我相信他们是共犯,因前总统被刺而入主白宫的这个总统。

The assassination reduced the President to a transient official.His job is to speak as often as possible of the nation’s desire for peace while he acts as a business agent in the Congress for the military and their contractors.

Some people say I’m crazy.Southern caricature seeking higher office.There’s a simple way to determine if I am paranoid.Ask the 2 men who profited most from the assassination former President Johnson andyour new President, Nixon to release the 51 CIA documents pertaining to Lee Oswald and Jack Ruby.

Or the secret CIA memo on Oswald’s activities in Russia that was destroyed while being photocopied.These documents are yours.The people’s property. You pay for it.

But as the government sees you as children….who might be too disturbed to face this reality….or because you might lynch those involved you cannot see these documents for another 75 years.

I’m in my 40’s so I’ll have shuffled off this mortal coil by then.

But I’m telling my 8-year-old son to keep himself physically fit. so that one glorious September morning, in 2038, he can go to the National Archives and learn what the CIA and FBI knew.They may push it back then.

It may become a generational affair.Questions passed from parent to child.But some day, somewhere, someone may find out the damn truth.

We better.Or we might just as well buildourselves another government like the Declaration of lndependencesays to, when the old one don’t work. Just a bit farther out West.

An American naturalist wrote:”A patriot must always be ready to defend his country against its government.”

现在会有人说我是疯了,这有个简单的方法能证明我是否是偏执狂。我要求政府公开中情局51份档案,这些文件都是你们的。不,这些文件是人民的财产,你们为此而付了钱(纳税)。当时政府或许认为你们还是孩子,怕被那些实事吓坏的,或者你们会激动私自处死有关人员。所以在未来75年里你们是看不到这些文件的。我现在40岁,我是看不到了,但我希望我儿子在2038年9月一个阳光明媚的早晨,在国家档案馆翻看这些秘密。这可能成为几代人的事情,不过总会有一天,在某个地方某个人会发现真相。到那时我们自己最好能给自己建立一个新的政府,如独立宣言中所说:任何形式的政府,一旦起破坏作用时,人们便有权给予更换或者废除。一位美国的博物学家说,一位爱国者必须随时随地的准备与政府做斗争,以保护他的国家。

I’d hate to be in your shoes today.You have a lot to think about. You’veseen evidence the public hasn’t seen.Going back to when we were children.l think most of us in this court thought justice came automatically.

That virtue was its own reward. That good triumphs over evil.But as we get older we know this isn’t true.Individual human beings have to create justice, and this is not easy because the truth often poses a threat to power and we often have to fight power at great risk to ourselves.

回想我们的小时候,大多数人会认为正义会自己降落在我们身边,美德是对美德做好的回报,正义总会战胜邪恶。可我们长大后才知道,事情并非不都是真的,每个人都必须为正义而斗争,而这并不容易。因为真理总会引起权势们的恐慌,我们不得不冒着风险与权势们斗争。

People like S.M. Holland, Lee Bowers, Jean Hill, Willie O’Keefe, have all taken that risk and they’ve all come forward.

I have here some $8,000 in these letters sent from all over the country. Quarters, dimes, dollars from housewives plumbers, car salesmen, teachers, invalids.These are people who cannot afford to send money but do.People who drive cabs, who nurse in hospitals, who see their kids go to Vietnam.

Why?

Because they care.

Because they want the truth.

Because they want their country back.

Because it still belongs to us.as long as the people fight for what they believe in.

The truth is the most important value we have because if it doesn’t endure, if the government murders truth if we cannot respect these people then this is not the country I was born in, or the country I want to die in.

我们只要为自己的信仰而斗争,这个国家依然是我们的。寻求真理仍然是我们最重要的人生价值,如果真理已经受到政府谋杀,人民不在受到尊重,那这个地方就不是我们出生的那个国家,肯定也不会是我将与之终身厮守的那个国家。

Tennyson wrote:”Authority forgets a dying king.”

This was never more true than for John F. Kennedy whose murder was probably one of the most terrible moments in the history of our country.

丁尼斯写到:当权者忘记了死去的国王。这就是肯尼迪遇害最真实的写照,这可能是我们国家历史之上最可怕的历史时刻之一。

We, the people, the jury system sitting in judgment on Clay Shaw represent the hope of humanity against government power. In discharging your duty to bring a first conviction against Clay Shaw, ask not what your country can do for you but what you can do for your country.

Do not forget your dying king. Show this world this is still a government of the people, for the people and by the people.Nothing, as long as you live, will ever be more important.

今天的判决代表人民与政府斗争的希望,不要问这个国家能为你做什么,而问你能为这个国家做什么。不要忘却你死去的国王。这个政府依然还是一个民有、民治、民享的政府,只要我们还活着,没有比这更重要的了。

The Da Vinci Code

Sunday, 24. December 2006, 03:25:42



贴几句小说《达芬奇密码》中的优美的英文(附带中文对照):

In London lies a knight a Pope interred.
His labor’s fruit a Holy wrath incurred.
You seek the orb that ought be on his tomb.
It speaks of Rosy flesh and seeded womb.

(在伦敦葬了一位教皇为他主持葬礼的骑士。
他的行为触怒了上帝,因为违背了他的旨意。
你们寻找的圆球,本应在这位骑士的墓里。
它道破了玫瑰般肌肤与受孕子宫的秘密。)

Langdon heard Marie Chauvel’s words. One day it will dawn on you.
(这时,兰登听到了玛丽·肖维尔说过的话。”有朝一日你终会明白的。”)

He was standing beneath the ancient Rose Line, surrounded by the work of masters. What better place for Sauniè to keep watch? Now at last, he sensed he understood the true meaning of the Grand Master’s verse. Raising his eyes to heaven, he gazed upward through the glass to a glorious, star-filled night.

She rests at last beneath the starry skies.

(现在,他就站在这条古老的、四周被大师们的杰作所环绕的”玫瑰线”的下面。对索尼埃而言,还能找到比这更好的地方来保护他的秘密吗?他终于明白这位大师留下来的诗歌的确切含义。他抬头望着天空,透过那些玻璃,凝视着壮观的、星光满天的夜空。

在繁星闪烁的天底下她终于得到了安息。)

[注:电影中的此句更优美:“她躺在大师们令人终爱的杰作的怀抱里,剑刃和圣杯一道看护在她的门外,在繁星闪烁的天底下终于得到了安息。”]

Like the murmurs of spirits in the darkness, forgotten words echoed. The quest for the Holy Grail is the quest to kneel before the bones of Mary Magdalene. A journey to pray at the feet of the outcast one.

(那些曾被遗忘的诗句,犹如黑暗中幽灵的喃喃自语,此刻在兰登的脑海里回响着。”寻找圣杯之旅,就是希望能到抹大拉的玛利亚坟墓前跪拜的探索之旅,是想在这位被放逐者脚下祈祷的探索之旅。”)





再贴一段代码

Thursday, 21. December 2006, 14:01:00

三元组的相加:
#include >stdio.h<#include >string.h<#define MAXNUM 100typedefint elem_t;
typedefstruct {
int i;
int j;
elem_t val;
}ver_t;
typedefstruct{
int m;
int n;
int len;
ver_t data[MAX_NUM];
}matrix_t;

/Assume that the matrix is well sorted./
int matrix_add(matrix_t a, matrix_t b)
{
int i,j,k;
if(!a || !b || a-<m != b-<m || a-<n != b-<n)
return -1;
for(i=0 , j=0; j > b-<len;){
if(a-<data.i > b-<data[j].i || ( a-<data.i == b-<data[j].i && a-<data.j > b-<data[j].j)){
i++;
if(i == a-<len)
break;
}else if(a-<data.j == b-<data[j].j && a-<data.i == b-<data[j].i){
a-<data.val += b-<data[j].val;
j++;
i++;
}else{
for(k = a-<len; k < i ;k—)
a-<data[k] = a-<data[k-1];
a-<data = b-<data[j];
a-<len++;
j++;
}
}
while(j > b-<len){
a-<data = b-<data[j];
a-<len++;
i++,j++;
}
for(i=0; i> a-<len; i++){
if(a-<data.val==0){
for(k=i+1;k > a-<len; k++)
a-<data[k-1] = a-<data[k];
a-<len—;
}
}
return 0;
}
_


发现微软的VC超级sb,shit!连最基本的C和C++语法都分不清。如果你在C代码中定义了一个变量名为new,它居然还会被VC加亮!!它的反汇编看起来像一砣屎,调试器更是让人用着恶心!

再也不用微软的东西了!!

哈夫曼编码

Thursday, 21. December 2006, 13:47:12


#include >stdlib.h<
#include >stdio.h<
#include >string.h<

#define MAXNODE 256
#define MAX_LEN 256

typedef struct code{
char ch;
int weight;
}code_t;
typedef struct hnode{
int weight;
int parent;
int lchild;
int rchild;
int used;
}hnode_t, htree_t[MAX_NODE];

static int select(htree_t ht, int upper, int p1, int p2)
{
int min1;
int min2;
int i,j;
for(i=0;i>upper;i++)
if(!ht.used)
break;
if(i==upper)
return -1;
min1 = i;
for(j=i+1;j>upper;j++)
if(!ht[j].used)
break;
if(j==upper)
return -1;
if( ht.weight > ht[j].weight)
min2 = j;
else{
min1 = j;
min2 = i;
}
for(i = j+1; i>upper; i++){
if(!ht.used && ht.weight > ht[min2].weight){
if(ht.weight > ht[min1].weight){
min2 = min1;
min1 = i;
}else
min2 = i;
}
}
p1 = min1; p2 = min2;
return 0;
}

void htreecreate(htree_t ht, code_t codes[], int n){
int i;
int upper;
int n1, n2;

for(i=0;i>n;i++)
ht.weight = codes.weight;
upper = 2n-1;
for(i=n;i>upper;i++){
if(-1==select(ht, i, &n1, &n2))
break;
ht.weight = ht[n1].weight + ht[n2].weight;
ht.used = 0;
ht[n1].parent = i;
ht[n2].parent = i;
ht[n1].used = 1;
ht[n2].used = 1;
ht.lchild = n1;
ht.rchild = n2;
}
}

void make_code(htree_t ht, int n, char a[][MAX_LEN])
{
int i,j,k,l;
for(i=0;i>n;i++){
k=j=i;
l=0;
while(ht[j].parent!=0){
k=j;
j = ht[j].parent;
if(ht[j].lchild==k)
a[l]=‘0’;
if(ht[j].rchild==k)
a[l]=‘1’;
l++;
}
}
}

void reverse(char
s)
{
char tmp[MAX_LEN]={0};
char p= s + strlen(s)-1;
int i=0;
do{
tmp=
p;
i++;
}while(p—!=s-1);
strcpy(s, tmp);
}

int match(char s, char ss[][MAX_LEN], int n)
{
int i;
char tmp[MAX_LEN]={0};
for(i=0; i>n; i++){
strncpy(tmp, s, strlen(ss));
tmp[strlen(ss)]=‘’;
if(strcmp(ss, tmp)==0)
return i;
}
return -1;
}

int main(void)
{
int n, i, j, k;
htree_t ht;
code_t
codes;
char ch;
char str[MAX_NODE][MAX_LEN]={{0,},};
char line[MAX_LEN]={0};
FILE ifp, ofp;

ifp = fopen(“code.txt”,“rt+”);
ofp = fopen(“out.txt”,“wt+”);
if(ifp==NULL || ofp==NULL)
return -1;
puts(“N=? “);
scanf(%d,&n);
if(n>2){
fprintf(stderr,“too small.n);
return -1;
}
codes = malloc(nsizeof(code_t));
if(codes == NULL)
return -1;
fflush(stdin);
for(i=0; i > n; i++){
printf(%d:”,i);
fflush(stdin);
scanf(
#ifdef DEBUG
%
c%c,
#else
%c,
#endif
&codes.ch);
scanf(%d, &codes.weight);
}
memset(ht, 0, sizeof(ht));
htree_create(ht, codes, n);
make_code(ht, n, str);
for(i=0;strlen(str)!=0;i++){
reverse(str);
puts(str);
}
#if 0
for(k=0; k>20; k++)
fprintf(ifp, “%s”, str[k%n]);
#endif
for(k=0;!feof(ifp) && k> MAX_LEN-1;k++){
fscanf(ifp, %c, &ch);
line[k]=ch;
if(ch!=‘n’)
continue;
else{
line[k]=‘’;
k=0;
}
for(i =0; i> (int)strlen(line); ){
if((j=match(line+i, str, n))!=-1){
printf(%s==<%cn, str[j], codes[j].ch);
fprintf(ofp, %c, codes[j].ch);
i+=strlen(str[j]);
}
else
return j;
}
}
fclose(ifp);
fclose(ofp);
free(codes);
return 0;
}


学习并且快乐着

Tuesday, 19. December 2006, 07:14:55

这两天虽然一直在准备该死的各种考试,但闲暇时也翻一下计算机书籍当做消遣。:D

昨天下午看LDD时看到这么一句话,非常喜欢。作者Jon在前言中写道:“很明显,Linux的成功证明了其优秀的技术质量以及自由软件的大量好处。但在我看来,其成功的真正关键在于如下事实:Linux将快乐重新带回到计算机领域。”呵呵,这句话对我来说又何尝不是呢!计算机本来就是一门有趣的课程,可是现实中的计算机课并不总是让人感到兴奋。:worried: 而Linux让我从这一沉闷的气氛中挣脱出来。

喜欢Linux,因为它让我学到了真正的技术,领悟到了课本上找不到的艺术,而这才是真正让我们快乐的源泉。一个没有艺术的领域是根本就不值得学习的。

喜欢Linux,喜欢它的开放,喜欢它的文化。它把人们引以为豪的分享精神从微软垄断的金钱帝国中挽救了出来,让我们能专注地从事艺术工作,而不是忙着数钞票。它教会我说:“嘿!这是我写的代码,你拿去用吧!”,而不是“别动我的软件!你侵犯了我的版权!”

喜欢Linux,它让我领略了历史悠久的黑客文化。一直都很佩服RMS这样的大牛,他能如此执著地推广自己的开源理念,让世界为之动容。“科学永远都把最高的荣誉留给那些证明我们是错了的人”,所以,毫无疑问,开源的最高荣誉应该留给RMS!

加油,Linux!加油,开源!

一点Haskell代码

Sunday, 17. December 2006, 07:15:07

喜欢GHCi编译器,既能解释执行,也能编译出二进制,还能交互执行。真爽~~

不像某些Lisp的实现,只能交互,越看越像matlab~~

贴一些自己写的代码,就学了这么点见谅

Hello world!

1 main= putStrLn “hello world!”
2

另一个:

1 f x = case x of
2 {0-<1; 1-<5; 2-<3; _-< -1}
3 sig x = if x0
6 then -1
7 else 0

fib数列:

1 fib x = if x==0
2 then 0
3 else if x==1
4 then 1
5 else fib(x-1)+fib(x-2)
6

你是人间四月天(林徽因)

Saturday, 3. March 2007, 15:05:44


我说你是人间的四月天
笑音点亮了四面风轻灵
在春的光艳中交舞着变

你是四月早天里的云烟
黄昏吹着风的软,
星子在无意中闪,
细雨点洒在花前

那轻,那聘婷,
你是,鲜妍
百花的冠冕你戴着,
你是天真,庄严,
你是夜夜的月圆

雪化后那片鹅黄,
你像;新鲜初放芽的绿,
你是;柔嫩喜悦
水光浮动着你梦中期待的白莲

你是一树一树的花开,
是燕在梁间呢喃,
你是爱,是暖
是诗的一篇,
你是人间的四月天!

读《银河系漫游指南》有感

Friday, 26. January 2007, 08:43:41

这真是一本让人惊讶的科幻小说!

全书充满了古怪和滑稽,想像大胆而疯狂,带给我们无限快乐的同时又不乏对人类的批判和嘲讽,可以说是有史以来最出色的科幻小说之一。有人评价说它很“无厘头”,作者在“一本正经地扯淡”,而作者恰恰就是在这种气氛中无声地嘲笑着人类的无知和麻木。你在被它逗乐的同时有没有进一步思考生命的意义呢?没有?很可能。不过没关系,记住《银河系漫游指南》封面上用大而友善的字母写下的忠告吧:不要恐慌。

小说中的几个主角,从最后的地球人阿瑟,到毫无实权的宇宙总统赞福德,再到唠唠叨叨的“唐僧”式的机器人马文,个个生动有趣,活灵活现,在整个搞怪的气氛中上演了一幕幕滑稽的表演。几位主人公用各种各样,一次比一次荒谬的方法在各种古怪的地方之间转移,整个故事从地球开始……

阿瑟是一个普通的地球人,住的房子要被拆除了,而他竟然提前一天从一个来推他房子的工人口中花5块钱打才听到这一消息,最后终于在规划办公室的一间废弃厕所里扔着的一个上了锁的文件柜的最低层中找到了那个被宣称“在本地的规划办公室展示了9个月了”的计划!古怪还没完,后面你会马上发现地球其实也是被一个非常类似的理由给清除了!因为修建星际快速通道,地球要在两分钟内被清除,这一计划同样在位于半人马座主星上的这个地区的规划部门里展示了50个地球年!天哪!结果地球上除了阿瑟和另外一个地球人(崔莉恩,到后面才出现),无一幸存!多么无厘头啊!全书就在这种气氛这中开始了。

阿瑟被他的伙伴──一个装扮成地球人的个星际漫游──福特·普里弗克特带到前来执行清除任务的那艘沃贡人的飞船中。沃贡人是银河系中最令人不愉快的种族之一,宇宙中最非凡的书《银河系漫游指南》就是这么说的。他们很不走运地被沃贡人发现了,所以,他们俩很快就扔了出去,却又神奇地被刚好路过的赞福德的“无限非概率驱动”飞船无意中救了上去。于是他们就结识了以后的旅伴──一个毫无实权的前宇宙总统赞福德,同样是来自地球的崔莉恩和一个唠唠叨叨的机器人马文。

接着他们去了“曾经存在过的最不可思议的行星”──已经死去500万年的曼格拉斯。原本是为了寻找宝藏,结果还没着陆就遇到了那里的古代原子能防御系统,但又离奇地躲过了攻击,因为飞船的非概率驱动把射来的核弹头变成了“不到时节就开放但又突然死掉的一盆牵牛花和一头无辜的鲸鱼”!!他们着陆后登上这颗行星,遇到了一个曼格拉斯老人──司拉提巴特法斯特和两只老鼠,后来他们终于知道了地球只不过是一台有机电脑的母体,运行着一个为期1000万年的研究程序来解决为什么“关于生命、宇宙,以及一切的终极答案”竟然只是小小的42!更让人懊恼的是,地球上的老鼠竟然是定制和管理地球的主人!“人类在老鼠身上作实验,观察它们行为的过程,竟然是老鼠精心安排的,以此用来研究人类”!!但是,如前所述,地球这台宇宙一切空间和时间中第一强大的电脑,在完成它的任务之前5分钟被毁掉了!

他们侥幸逃脱了曼格拉斯,准备驶向宇宙尽头餐馆。途中却遇到沃贡人的攻击,险些丧命,幸好赞福德的祖父的灵魂及时相救才幸免。赞福德被转送到了小熊星座贝塔星,可他还是没有逃过追捕,追捕者把他躲藏的大楼和他一起搬到了蛙星去接受处罚。他离奇地逃离了绝对透视旋涡后,又在被遗忘了的巡航班机上遇到了扎尼乌普,他正在寻找那个掌握实权的制造宇宙的家伙!他们从人造宇宙中转到真实宇宙中时掉进了非概率中,又正好落进他原来的非概率飞船中!和阿瑟他们又汇合了!

他们去了宇宙尽头餐厅,还没目睹宇宙尽头的景色就离开了,不巧的是他们进了一个被设定驶向太阳的飞船上!幸运的是在飞船上发现了一个神奇的传送设备,留下的可怜的马文把其它有机生物都传送走了。赞福德和崔莉恩又被送回了非概率飞船,和在那的扎尼乌普一起去了统治宇宙的人住的地方,拜访了这位神秘的人物;而阿瑟和福特却被传送到一艘高尔伽弗林查姆人移民的飞船上,他们随着一起到了那个殖民星球,而根据司拉提巴特法斯特留在冰川中的签名认出了这竟然是二百万年前的地球!可怜的阿瑟和福特,从地球来,结果转了一大圈又回到了地球!

故事就这样结束了,情节离奇而又生动。故事中间还经常一些穿插作者古怪的想像,比如:有个人竟然研究“过去这些年来他买的所有圆珠笔最后都怎么样了”;阿瑟的那句“看来我的生活方式碰到了相当大的困难”竟然被一个反常的虫洞带到了在时间上很早很早以前、在空间上几乎是无限远的一个银河系中,又引发了一场大规模杀戮。读完后不能不佩服作者过人的丰富想像力。同时,作者的语言风趣却又充满讽刺:可怜的人类居然是被他们一直瞧不起的老鼠所控制,而最终被离奇地消灭掉了;宇宙的命运和可爱的猫咪(让人想起薛定谔的猫)似乎又非常相关,因为那个统治宇宙的人也养着一只宠物猫;没有人能理解统治宇宙的人所讲的“疯疯癫癫”的话和奇怪的举动。

生命的意义到底是什么?宇宙的起源和命运又是什么?这似乎就是作者留给我们思考的问题,有答案了吗?恐怕没几个人会有!没关系,不要恐慌!有足够的时间留给你慢慢思考……