2007年4月1日 星期日

Lesson 0: Scheme is weird

Remember that. Scheme is weird. But sometimes there is a reason. Let's write a java program to get a number from the user, add 13 to it, and print it out. We'll pretend we already have a function called System.in.getNumber() to do the first step:

Double number = System.in.getNumber();
number += 13;
System.out.println number;


We tell the computer what to do in exactly the order it should be done, just the way we do things in real life, one step at a time. But there is sometimes a problem. When we are all the way down at the end, maybe the value of number has changed. Where did it come from? This is especially hard if you name variables things like i or bg_f. What does that mean? How do you know it hasn't changed somewhere else in the program?

More importantly, it's hard to see what the goal if this program is. It doesn't tell us what we really want to do until the very end.

In scheme, instead of using lots of ='s and variables, we do something different. We write programs with the name of a function first, and the arguments to the function inside it, like this: (+ 1 2), which is the same as Java's 1 + 2 or (or x y) which is the same as Java's x || y [Edit: fixed this, thanks taishen!]. Keeping in mind that the function name cames first, and the arguments inside it, let's see that program in Scheme:

(print (+ 13 (get-number)))

Notice that this program is inside-out. It says the end goal first: we want to print something. What do we want to print? 13 plus something, where something comes from the function get-number.

Make sense? Maybe not. For your first assignment, go read section 1.1.1 and 1.1.2 in the textbook. If you have questions, try using an online English-Chinese computer terms dictionary, or ask in the comments.

第一篇

各位學生你好!

我們的scheme課程快要開始阿。目的不是學習一定 的電腦語言而且明白最基本的資工方式。scheme那個語言很特別,跟java差很多,所以假如java,scheme都明白,你不只是模仿課本但是真的明白。

很辛苦,我們必須用英文因為網上所有 的資料都用英文。假如有問題,國語還可以,但是每兩個詞應該是英文的專詞。

開始如下:
  1. 下裁Dr. Scheme, Windows, OS X, Linux都可以。第一次必須選語言,用Langyage > Choose Langyage > Standard 就案ok.
  2. 網上有課本: MITPress.


最後一個問題:為什麼用scheme呢?這是什麼怪怪的東西?你聽過MIT的名稱嗎?Harvard呢?臺大呢?他們的基本課程都以scheme(還是scheme的哥哥lisp)為題。想一想。