1.阅读David Turner-Some History of Functional Programming Languages。
2.阅读a history of Haskell,了解函数语言发展的历史。
3.下载并安装Racket(https://www.racket-lang.org/),为第4步编写调试程序配置好编程环境。
安装完后点击Language->Choose Language
引入包,点击Language->Add Teachpack:
选择引入图片2htdp/image和动画2htdp/universe: animate
4.阅读Matthias Felleisen编写的教材《How To Design Programs》的PROLOGUE: HOW TO PROGRAM部分,编写并调试成功类似下边程序,尝试修改程序让火箭在不同方向飞行(火箭图片用含有自己姓名的小图片代替)。(注:Matthias Felleisen是著名的程序语言专家,曾获得过ACM程序设计语言杰出成就奖)
源码:
; properties of the “world” and the descending rocket
(define WIDTH 100)
(define HEIGHT 500)
(define V 10)
(define X 50)
; graphical constants
(define MTSCN (empty-scene WIDTH HEIGHT))
(define ROCKET
)
(define ROCKET-CENTER-TO-TOP
(- HEIGHT (/ (image-height ROCKET) 2)))
(define ROCKET-CENTER-TO-width
(- WIDTH (/ (image-width ROCKET) 2)))
; functions
(define (picture-of-rocket.v6 t)
(cond
[(<= (distance t) ROCKET-CENTER-TO-TOP)
(place-image ROCKET (distanceX t) (distance t) MTSCN)]
[(> (distance t) ROCKET-CENTER-TO-TOP)
(place-image ROCKET (distanceX t) ROCKET-CENTER-TO-TOP MTSCN)]))
; 计算高度
(define (distance t)
(* V t))
; 计算左右浮动
(define (distanceX t)
(* X (sin (/ t 10))))
(animate picture-of-rocket.v6)
实验效果:
图片以Cos x函数轨迹运动