How to Design Programs
一些基本的函数
String
string-append :将多个string连接起来
>(string-append "hello" "word") helloword
string-length :计算string的字符个数
>(string-length "helloword") 9
string->number: 将string转化成数字
> (string->number "42") 42string=? : 判断string是不是一样的
> (string=? "hello" "hello") #t > (string=? "hello" "Hello") #fstring-ith : 返回一个字符串第几个位置出现的字符
> (string-ith "hello world" 1) "e"
boolean
and :同时为T的时候为真
> (and #t #t) #t > (and #f #t) #for : 有一个以上T的时候为真
> (or #t #f) #t > (or #f #f) #fnot : 取反 ,真时为假,假时为真
> (not #f) #t > (not #t) #f也可以用数学判断符号
> (> 10 9) #true > (< -1 0) #true > (= 42 9) #false注意scheme中的= , 不是其他语言中的赋值,而字面上的意思,判断操作数是否相等,和其他语言的==差不多,可是也有不同。
int
+
-
*
/
abs
> (abs 1) 1 > (abs -1) 1绝对值
add1
> (abs 1) 1 > (abs -1) 1加一
ceiling
> (ceiling 12.3) 13.0 > (ceiling 14.3) 15.0 > (ceiling 14) 14大于参数的最小整数
denominator
> (denominator 2/4) 2 > (denominator 2/6) 3 > (denominator 2/2) 1 > (denominator 2/7) 7 > (denominator (/ 2 7)) 7 > (denominator (/ 2 9)) 9 > (denominator 0.5) 2.0Computes the denominator of a rational.计算有理数的分母
exact->inexact
> (exact->inexact 0.9) 0.9 > (exact->inexact 222) 222.0 > (exact->inexact 22233) 22233.0 > (exact->inexact 1/3) 0.3333333333333333 > (exact->inexact (/ 1 3)) 0.3333333333333333将精确的数字变成不精确的
expt
> (expt 1 2) 1 > (expt 2 2) 4 > (expt 2 3) 8 > (expt 6 3) 216 > (expt 2 10) 1024(expt x y) 计算x的y次方
floor
> (floor 1.2) 1.0 > (floor 1.7) 1.0 > (floor 1.3) 1.0 > (floor -1.3) -2.0小于参数的最大整数
gcd
> (gcd 10 15 20) 5 > (gcd 10 15 22) 1 > (gcd 10 15 24) 1 > (gcd 10 15 25) 5 > (gcd 12 15 24) 3计算最大公约数
log
> (log 2.8) 1.0296194171811581 > (log 2.71) 0.9969486348916096 > (log 2.72) 1.000631880307906 > (log 2.712) 0.9976863700781492 > (log 2.713) 0.9980550336767947 > (log 2.713) 0.9980550336767947计算log值
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!