2007/08/19

Hello World in CWEB

十點多就寢,十二點多就醒了,於是起床試玩 CWEB,寫了個 hello, world。成果 pdf 請點 external link。以下摘錄我在這個程式(literate program)最後寫的感想:

My comments after finishing the first CWEB program: it's truly fun. The feeling of writing, or rather, composing a program is quite different from my old approach(es). Still I think it takes time (which means lots of practice) to get accustomed to and make full use of CWEB. And before I can master Chinese typesetting in TeX and perhaps modify the source of CWEB, programming under CWEB is going to improve my technical English writing, for sure. Also I may be able to pick up vim and make this time, possibly along with other "old-fashioned" tools.

CWEB source:

@i c++lib.w

\def\CWEB{{\tt CWEB}}
\font\eighttt=cmtt8
\def\title{Hello World in {\eighttt CWEB}}
\def\topofcontents{\null\vfill
  \centerline{\titlefont Hello World in {\ttitlefont CWEB}}
  \vfill}

@* Hello World. This is my first \CWEB\ program in \CPLUSPLUS/, starting from
the classical ``hello, world''. The program is actually too trivial to be
written in \CWEB. In fact, writing it in \CWEB\ may have unnecessarily
increased its complexity. Anyway, the structure of the entire program is as
follows.

@c
@<header inclusion@>@;

int main() {
  @<say ``hello, world''@>;
}

@ We need only one header for this simple program, namely {\tt <iostream>} for
writing the string ``hello, world'' to the terminal. We do not give a |using|
directive for namespace |std| as customarily done in very small programs since
this is going to save some typing (in the code).

@<header...@>=
#include <iostream>

@ The central part is the only one statement that outputs the string ``hello,
world''. The format of the string (all letters in lowercase, a comma as the
only punctuation, etc.) is kept loyal to Kernighan and Ritchie's {\sl The C
Programming Language}.

@<say...@>=
std::cout << "hello, world" << std::endl;

@* Comments. My comments after finishing the first \CWEB\ program: it's truly
fun. The feeling of writing, or rather, {\it composing} a program is quite
different from my old approach(es). Still I think it takes time (which means
lots of practice) to get accustomed to and make full use of \CWEB. And before
I can master Chinese typesetting in \TeX\ and perhaps modify the source of
\CWEB, programming under \CWEB\ is going to improve my technical English
writing, for sure. Also I may be able to pick up {\tt vim} and {\tt make} this
time, possibly along with other ``old-fashioned'' tools.

--
連寫 hello, world 都有種莫名的成就感 XD。


A screenshot for those who don't want to download the pdf:


勘誤:書名(namely "The C Programming Langauge")改用 slanted font(instead of italic one)。


再勘誤:應該 @i c++lib.w

Labels:

Blogger yen38/20/2007 5:52 am 說:

這發文的時間還真是莫名的恐怖 XD

 

<< 回到主頁