Marvin's Blog【程式人生】

Ability will never catch up with the demand for it

21 Feb 2021

The Scheme Programming Language读书笔记【六】

The Scheme Programming Language 读书笔记,chapter 6下半部.

Chapter 6. Operations on Objects

Section 6.7. Characters

字符是原子性的对象,用来表示字母,数字字符,特殊名号比如$或者-,以及其他一些非图形的控制字符,比如空格和新行。

字符以#\位前缀,例如:

  • #\A
  • #\tab
  • #\newline
  • #\space
  • #\xnn为unicode码点

相关比较用的执行诀:

  • (char=? char1 char2 char3 ...)
  • (char<? char1 char2 char3 ...)
  • (char>? char1 char2 char3 ...)
  • (char<=? char1 char2 char3 ...)
  • (char>=? char1 char2 char3 ...)

大小写不敏感的比较用的执行诀:

  • (char-ci=? char1 char2 char3 ...)
  • (char-ci<? char1 char2 char3 ...)
  • (char-ci>? char1 char2 char3 ...)
  • (char-ci<=? char1 char2 char3 ...)
  • (char-ci>=? char1 char2 char3 ...)

其他:

  • (char-alphabetic? char)
  • (char-numeric? char)
  • (char-whitespace? char)
  • (char-lower-case? char)
  • (char-upper-case? char)
  • (char-title-case? char)
  • (char-general-category char),Unicode general category
  • (char-upcase char)
  • (char-downcase char)
  • (char-titlecase char)
  • (char-foldcase char)
  • (char->integer char)
  • (integer->char char)

Section 6.8. Strings

字串,由字符组成,语法上使用双引号划定,例如"hi there”。\可以用作转义字符,在字符串内生成单个双引号\",或者自身\\,还有\r\n等特殊字符。使用#\xn可以插入Unicode码点。

相关执行诀:

  • (string=? string1 string2 string3 ...)
  • (string<? string1 string2 string3 ...)
  • (string>? string1 string2 string3 ...)
  • (string<=? string1 string2 string3 ...)
  • (string>=? string1 string2 string3 ...)
  • (string-ci=? string1 string2 string3 ...)
  • (string-ci<? string1 string2 string3 ...)
  • (string-ci>? string1 string2 string3 ...)
  • (string-ci<=? string1 string2 string3 ...)
  • (string-ci>=? string1 string2 string3 ...)
  • (string char ...),从多个字符生成字串
  • (make-string n)
  • (make-string n char)
  • (string-length string)
  • (string-ref string n) 返回第n个字符
  • (string-set! string n char)
  • (string-copy string)
  • (string-append string ...)
  • (substring string start end)
  • (string-fill! string char),将字串内的所有单字替换成char
  • (string-upcase string)
  • (string-downcase string)
  • (string-foldcase string), string-foldcase does not use the special mappings for Turkic languages
  • (string-titlecase string)
  • (string-normalize-nfd string), Unicode normalized form D
  • (string-normalize-nfkd string),Unicode normalized form KD
  • (string-normalize-nfc string),Unicode normalized form C
  • (string-normalize-nfkc string),Unicode normalized form KC
  • (string->list string)
  • (list->string list)

Section 6.9. Vectors

串列支持随机访问,这方面比连对要强。串列的索引从0开始。其语法形式是#(a b c)

相关执行诀:

  • (vector obj ...)返回一个串列
  • (make-vector n)
  • (make-vector n obj)
  • (vector-length vector)
  • (vector-ref vector n)
  • (vector-set! vector n obj)
  • (vector-fill! vector obj)
  • (vector->list vector)
  • (list->vector list)
  • (vector-sort predicate vector),对predicate的调用有nlogn的要求
  • (vector-sort! predicate vector),对predicate的调用有n**2的要求

Section 6.10. Bytevectors

用来表示二进制数据。表示上通常采用一串8比特无符号数串列,但是一个bytevector可以用来表示一串有符号8比特数,也可以是16位,32位,64位甚至是任意精度。连IEEE单双精度浮点数,以及前述任意组合的串列。

形式上,字节串列的写法以#vu8为前缀,如#vu8(1 2 3)

相关执行诀:

  • (endianness symbol),用于设置大小端
  • (native-endianness)
  • (make-bytevector n)
  • (make-bytevector n fill)
  • (bytevector-length bytevector)
  • (bytevector=? bytevector1 bytevector2)
  • (bytevector-fill! bytevector fill)
  • (bytevector-copy bytevector)
  • (bytevector-copy! src src-start dst dst-start n)
  • (bytevector-u8-ref bytevector n)
  • (bytevector-s8-ref bytevector n)
  • (bytevector-u8-set! bytevector n u8)
  • (bytevector-s8-set! bytevector n s8)
  • (bytevector->u8-list bytevector)
  • (u8-list->bytevector list)
  • (bytevector-u16-native-ref bytevector n)
  • (bytevector-s16-native-ref bytevector n)
  • (bytevector-u32-native-ref bytevector n)
  • (bytevector-s32-native-ref bytevector n)
  • (bytevector-u64-native-ref bytevector n)
  • (bytevector-s64-native-ref bytevector n)
  • (bytevector-u16-native-set! bytevector n u16)
  • (bytevector-s16-native-set! bytevector n s16)
  • (bytevector-u32-native-set! bytevector n u32)
  • (bytevector-s32-native-set! bytevector n s32)
  • (bytevector-u64-native-set! bytevector n u64)
  • (bytevector-s64-native-set! bytevector n s64)
  • (bytevector-u16-ref bytevector n eness)
  • (bytevector-s16-ref bytevector n eness)
  • (bytevector-u32-ref bytevector n eness)
  • (bytevector-s32-ref bytevector n eness)
  • (bytevector-u64-ref bytevector n eness)
  • (bytevector-s64-ref bytevector n eness)
  • (bytevector-u16-set! bytevector n u16 eness)
  • (bytevector-s16-set! bytevector n s16 eness)
  • (bytevector-u32-set! bytevector n u32 eness)
  • (bytevector-s32-set! bytevector n s32 eness)
  • (bytevector-u64-set! bytevector n u64 eness)
  • (bytevector-s64-set! bytevector n s64 eness)
  • (bytevector-uint-ref bytevector n eness size)
  • (bytevector-sint-ref bytevector n eness size)
  • (bytevector-uint-set! bytevector n uint eness size)
  • (bytevector-sint-set! bytevector n sint eness size)
  • (bytevector->uint-list bytevector eness size)
  • (bytevector->sint-list bytevector eness size)
  • (uint-list->bytevector list eness size)
  • (sint-list->bytevector list eness size)
  • (bytevector-ieee-single-native-ref bytevector n)
  • (bytevector-ieee-double-native-ref bytevector n)
  • (bytevector-ieee-single-native-set! bytevector n x)
  • (bytevector-ieee-double-native-set! bytevector n x)
  • (bytevector-ieee-single-ref bytevector n eness)
  • (bytevector-ieee-double-ref bytevector n eness)
  • (bytevector-ieee-single-set! bytevector n x eness)
  • (bytevector-ieee-double-set! bytevector n x eness)

Section 6.11. Symbols

名号和字串有点类似,不过名号之间进行对比的话,其效率比字串对比要高得多。只需要使用eq?即可。

相关执行诀:

  • (symbol=? symbol1 symbol2)
  • (string->symbol string)
  • (symbol->string symbol)

Section 6.12. Booleans

相关执行诀:

  • (boolean=? boolean1 boolean2)

Section 6.13. Hashtables

哈希表用来在任意两个scheme值之间建立关联,跟关联列表有点像,但是在数据量大的时候性能更好。

相关执行诀:

  • (make-eq-hashtable)
  • (make-eq-hashtable size)
  • (make-eqv-hashtable)
  • (make-eqv-hashtable size)
  • (make-hashtable hash equiv?)
  • (make-hashtable hash equiv? size)
  • (hashtable-mutable? hashtable)
  • (hashtable-hash-function hashtable)
  • (hashtable-equivalence-function hashtable)
  • (equal-hash obj)
  • (string-hash string)
  • (string-ci-hash string)
  • (symbol-hash symbol)
  • (hashtable-set! hashtable key obj)
  • (hashtable-ref hashtable key default)
  • (hashtable-contains? hashtable key)
  • (hashtable-update! hashtable key procedure default)
  • (hashtable-delete! hashtable key)
  • (hashtable-size hashtable)
  • (hashtable-copy hashtable)
  • (hashtable-copy hashtable mutable?)
  • (hashtable-clear! hashtable)
  • (hashtable-clear! hashtable size)
  • (hashtable-keys hashtable)
  • (hashtable-entries hashtable)

Section 6.14. Enumerations

(define-enumeration name (symbol ...) constructor用于创建枚举。例子:

(define-enumeration weather-element
(hot warm cold sunny rainy snowy windy)
weather

相关执行诀:

  • (make-enumeration symbol-list)
  • (enum-set-constructor enum-set)
  • (enum-set-universe enum-set)
  • (enum-set->list enum-set)
  • (enum-set-subset? enum-set1 enum-set2)
  • (enum-set=? enum-set1 enum-set2)
  • (enum-set-member? symbol enum-set)
  • (enum-set-union enum-set1 enum-set2)
  • (enum-set-intersection enum-set1 enum-set2)
  • (enum-set-difference enum-set1 enum-set2)
  • (enum-set-complement enum-set)
  • (enum-set-projection enum-set1 enum-set2)
  • (enum-set-indexer enum-set)

(本篇完)

Categories

Tags