I begun to read the htdp about 1 week ago.It's a amazing book that give you a way to explain what is computing by simplicity.The implementation of the computing cases are used by a little old computer language which is scheme that invented by Gerald Sussman who is a great computer science professor in MIT.Lisp is the second oldest language in computer field which designed by John McCarthy who is a student of Alonzo Church that he is a author of lambda calculus.Scheme is one of the best dialect of lisp.

How to Design Program?

perhaps people got their answers.As a newbie monkey coder thought that htdp would give you a big help.You have to forget what you knew.A lots sucks infos in your mind aNd you need blow it away.Like Sussman said"it's not about computer and program.it's all about computing."When I was a student in college,people just talk about j2EE,.net and microsfot something.That almostly bullshit!We need looking for the truth from computing world.htdp and sicp would provide a chance to know that truth,make a choice?

btw:words from a friend(non-christian) suddenly came into my mind"Even for our next generations kids,we have to hold the Free Software hood."

I was picks some interesting excersises,let's see:

;; The first three lines of this file were inserted by DrScheme. They record metadata

;; about the language level of this file in a form that our tools can easily process.

#reader(lib "htdp-advanced-reader.ss" "lang")((modname fah) (read-case-sensitive #t) (teachpacks ((lib "convert.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "convert.ss" "teachpack" "htdp")))))

;Exercise 2.2.1. Define the program Fahrenheit->Celsius,6 which consumes a temperature measured in Fahrenheit and produces the Celsius equivalent. Use a chemistry or physics book to

;look up the conversion formula.

(define Fahrenheit->Celsius (lambda

(Fahrenheit)

(* (/ 5 9) (- Fahrenheit 32))))

; Contract: area-of-ring : number number -> number

; Purpose: to compute the area of a ring whose radius is

; outer and whose hole has a radius of inner

; Example: (area-of-ring 5 3) should produce 50.24

; Definition: [refines the header]

(define area (lambda (r)

(* 3.14 (* r r))))

(define area-of-ring (lambda (outer inner)

(- (area outer)

(area inner))))

;Exercise 2.2.4. Define the program convert3. It consumes three digits, starting with the least

;significant digit, followed by the next most significant one, and so on. The program produces the

;corresponding number. For example, the expected value of

; (convert3 1 2 3)

;is 321. Use an algebra book to find out how such a conversion works.

(define convert3 (lambda (x y z)

(+ (* x 1) (* y 10) (* z 100))))

Exercise 3.1.4. After studying the cost structure of a show, the owner discovered several ways

of lowering the cost. As a result of his improvements, he no longer has a fixed cost. He now

simply pays $1.50 per attendee.

; profit : number -> number

; to compute the profit as the difference between revenue and costs

; at some given ticket-price

(define profit (lambda (ticket-price)

(- (revenue ticket-price)

(cost ticket-price))))

;; revenue : number -> number

;; to compute the revenue, given ticket-price

(define revenue (lambda (ticket-price)

(* (attendees ticket-price) ticket-price)))

;; cost : number -> number

;; to compute the costs, given ticket-price

(define cost (lambda (ticket-price)

(* 1.5 (attendees ticket-price))))

;; attendees : number -> number

;; to compute the number of attendees, given ticket-price

(define attendees (lambda (ticket-price)

(+ 120

(* (/ 15 0.1) (- 5 ticket-price)))))

;Exercise 3.3.1. The United States uses the English system of (length) measurements. The rest

;of the world uses the metric system. So, people who travel abroad and companies that trade with

;foreign partners often need to convert English measurements to metric ones and vice versa.

;Here is a table that shows the six major units of length measurements of the English system:

; English metric

; 1 inch = 2.54 cm

; 1 foot = 12 in.

; 1 yard = 3 ft.

; 1 rod = 5(1/2) yd.

; 1 furlong = 40 rd.

; 1 mile =8 fl.

;Develop the functions inches->cm, feet->inches, yards->feet, rods->yards, furlongs->rods, and miles->furlongs.

(define inch-cm 2.54)

(define foot-inch 12)

(define yard-feet 3)

(define rod-yard 5.5)

(define furlong-rod 40)

(define mile-furlong 8)

;;functions definition

(define inches->cm (lambda (inches)

(* inches inch-cm)))

(define feet->inches (lambda (feet)

(* feet foot-inch)))

(define yards->feet (lambda (yards)

(* yards yard-feet)))

(define rods->yards (lambda (rods)

(* rods rod-yard)))

(define furlongs->rods (lambda (furlongs)

(* furlongs furlong-rod)))

(define miles->furlongs (lambda (miles)

(* miles mile-furlong)))

;Then develop the functions feet->cm, yards->cm, rods->inches, and miles->feet.

(define feet->cm (lambda (feet)

(inches->cm

(feet->inches feet))))

(define yards->cm (lambda (yards)

(inches->cm

(feet->inches

(yards->feet yards)))))

(define rods->inches (lambda (rods)

(feet->inches

(yards->feet

(rods->yards rods)))))

(define miles->feet (lambda (miles)

(yards->feet

(rods->yards

(furlongs->rods

(miles->furlongs miles))))))

;Exercise 3.3.5. Develop the program height, which computes the height that a rocket reaches

;in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g · t

;in t time units and a height of 1/2 * v * t where v is the speed at t.

;a constant for acceleration

(define g 5)

;speed of g * t

(define speed (lambda (t)

(* g t)))

;height of /1/2 * v * t

(define height (lambda (t)

(* 0.5 (speed t) t)))

## Friday, March 13, 2009

### my gentoo

Linux has a lot of distros around the world.The first time I used Linux is Red hat 9,then I was turning into debian.I have use Fedora in past 2 years.Becuase it's pretty easy to use which is it doesnt needed spend more time for compile the source code by youself.

Today is a big day.I have try out install the most difficult linux i ever heard---gentoo.A friend told me that it is a real hacker's distro.Although it's none of business about whether you are a hacker and which linux distro you using.ANd it still worthy to try.Im installed the gentoo in VirtualBox which is a virtual machine software developed by Sun Microsystem(also under GPLv2).I was watching a movie which named of Revolution OS while it compiling the gentoo kernel.what a enjoy life!

Here's a screenshot:

gentoo is cool,about should i turn to it(nake host)?I have to think about it.Before make a decision about which distro i will use.The htdp's excersise has the higher priority I have to take it out!May Lord bless!

Today is a big day.I have try out install the most difficult linux i ever heard---gentoo.A friend told me that it is a real hacker's distro.Although it's none of business about whether you are a hacker and which linux distro you using.ANd it still worthy to try.Im installed the gentoo in VirtualBox which is a virtual machine software developed by Sun Microsystem(also under GPLv2).I was watching a movie which named of Revolution OS while it compiling the gentoo kernel.what a enjoy life!

Here's a screenshot:

gentoo is cool,about should i turn to it(nake host)?I have to think about it.Before make a decision about which distro i will use.The htdp's excersise has the higher priority I have to take it out!May Lord bless!

Subscribe to:
Posts (Atom)