Functions
Racket 语言
Racket被用于脚本程序设计、通用程序设计、计算机科学教育和学术研究等不同领域。
(define (add-twice a b) (+ a (* 2 b))). [函数名 形参 运算规则]
(define (huh? x) (+ x 2))
a函数用在b函数的里面,a函数的定义写在后面。
定义constant写在前面。
argument: (f 2 3). 指真实去算的数2 3
parameter: (f x y) 指形参
一些函数的用法:
>(integer-sqrt 5)
2
> (integer-sqrt -4.0)
0.0+2.0i
>(expt 9 1/2)
3
> (expt 9 0.5)
3.0
> (log (exp 1))
1.0
> (log 2+3i)
1.2824746787307684+0.982793723247329i
> (log 1)
0
> (log 100 10)
2.0
remainder 取余数
Design recipe
The design and organize process before coding.
写代码的顺序:
Header: The header is the whole function except for the body expression. Most importantly, it includes the function name and parameter names.
The contract: what type of data the function consumes and what type of data it produces.
ex.
作业题头要求
;;
;; ***************************************************
;; Rick Sanchez (12345678)
;; CS 135 Fall 2020
;; Assignment 03, Problem 4
;; ***************************************************
;;