Monday, August 10, 2009

My new blog address

http://angela22nest.spaces.live.com/

Wednesday, April 22, 2009

An important day!

Today, I successfully passed my MS thesis defense. ~~

Friday, April 10, 2009

We went to Austin!



Tuesday, April 7, 2009

OCaml file manipulation

The normal way of opening a file in OCaml returns a channel. There are two kinds of channels:

channels that write to a file: type out_channel
channels that read from a file: type in_channel

Writing

For writing into a file, you would do this:
1. Open the file to obtain an out_channel
2. Write stuff to the channel
3. If you want to force writing to the physical device, you must flush the channel, otherwise writing will not take place immediately.
4. When you are done, you can close the channel. This flushes the channel automatically.

Commonly used functions: open_out, open_out_bin, flush, close_out, close_out_noerr
Standard out_channels: stdout, stderr

Reading

For reading data from a file you would do this:
1. Open the file to obtain an in_channel
2. Read characters from the channel. Reading consumes the channel, so if you read a character, the channel will point to the next character in the file.
3. When there are no more characters to read, the End_of_file exception is raised. Often, this is where you want to close the channel.
Commonly used functions: open_in, open_in_bin, close_in, close_in_noerr
Standard in_channel: stdin

Example

open Printf

let file = "example.dat"
let message = "Hello!"

let _ =

(* Write message to file *)
let oc = open_out file in (* create or truncate file, return channel *)
fprintf oc "%s\n" message; (* write something *)
close_out oc; (* flush and close the channel *)

(* Read file and display the first line *)
let ic = open_in file in
try
let line = input_line ic in (* read line from in_channel and discard \n *)
print_endline line; (* write the result to stdout *)
flush stdout; (* write on the underlying device now *)
close_in ic (* close the input channel *)

with e -> (* some unexpected exception occurs *)
close_in_noerr ic; (* emergency closing *)
raise e (* exit with error: files are closed but
channels are not flushed *)

(* normal exit: all channels are flushed and closed *)

An interesting puzzle (from my comp409 homework)


There are five houses in five different colors. In each house lives a man with a different
nationality. The five owners drink a certain type of beverage, smoke a certain brand of cigar,
and keep a certain pet. No owners have the same pet, smoke the same brand of cigar or drink
the same beverage. The question is: “Who owns the fish?”
Hints:
• The Brit lives in the red house.
• The Swede keeps dogs as pets.
• The Dane drinks tea.
• The green house is on the left of the white house.
• The green house’s owner drinks coffee.
• The person who smokes Pall Mall rears birds.
• The owner of the yellow house smokes Dunhill.
• The man living in the center house drinks milk.
• The Norwegian lives in the first house.
• The man who smokes Blends lives next to the one who keeps cats.
• The man who keeps the horse lives next to the man who smokes Dunhill.
• The owner who smokes Bluemasters drinks beer.
• The German smokes Prince.
• The Norwegian lives next to the blue house.
• The man who smokes Blends has a neighbor who drinks water.
In order to solve the puzzle, you have to make some assumptions:
1. The owner is the resident of each house.
2. One of the residents owns the fish.
3. The term neighbor in the last hint refers only to a directly adjacent neighbor.
4. The houses are on the same side of the street.
5. They are next to each other, and are ordered from left to right as you face them rather
than standing in front of a house facing the street (i.e. facing the same direction as the
house).

Monday, April 6, 2009

From the foundering of the Vasa

Vasa (or Wasa) was a warship that was built for King Gustavus Adolphus of Sweden from 1626 to 1628. The ship foundered and sank after sailing less than a nautical mile (ca 2 km) into her maiden voyage on 10 August 1628.

Vasa was built top-heavy with insufficient ballast. Despite an obvious lack of stability in port, she was allowed to set sail and foundered a few minutes later when she first encountered a wind stronger than a breeze. The impulsive move to set sail resulted from a combination of factors. King Gustavus Adolphus, who was abroad on the date of her maiden voyage, was impatient to see Vasa join the Baltic fleet in the Thirty Years' War. At the same time, the king's subordinates lacked the political courage to discuss the ship's structural problems frankly or to have the maiden voyage postponed. The sinking of Vasa is a mishap in project management, QA testing and design. Due to these, the ships were fated for imminent disaster.


The Vasa is a classic engineering failure story. It is also a practical story that directly relates to people within engineering and technology disciplines. In many ways, as Kode Vicious points out, nothing has changed since 1628: People still fail to communicate, leading to failures of disastrous proportions. Egos get in the way, and mysterious supernatural forces are blamed for human failings.

A question, then, is: What can you do if your manager, or advisor, or superior is impatient?

[To be continued]

Thursday, April 2, 2009

Where God guides, God provides!



[following cited from: http://www.rbc.org/odb/odb.shtml]

Whenever the Lord assigns us a difficult task, He gives us what we need to carry it out. John Wesley wrote, “Among the many difficulties of our early ministry, my brother Charles often said, ‘If the Lord would give me wings, I’d fly.’ I used to answer, ‘If God bids me fly, I will trust Him for the wings.’”

If God has given you some special work to do that frightens you, it’s your responsibility to jump at it. It’s up to the Lord to see you through. As you faithfully do your part, He will do His part. — Richard De Haan