DataStructure
简单数据类型
- booleans
- number
- characters
- symbols
boolean, number and character is self-operation, it will callback the same data in other words.
Booleans
- Type: #f, #t
- Judgment: boolean?
- Operation: not
Scheme会把任何的非**#f##看成**#t**
Numbers
- Type: integer, rational, real, complex
- Judgment: number?, complex?, real?, rational?, integer?
- Declaration: rank-2: #b; rank-8: #o; rank-16: #x
- Operation: > < >= <= = + - * /
1 | (eqv? 42 42) ; ==> #t |
More Mathmetic Operation Recorded by Revised^6 Report on the Algorithmic Laguage Scheme
Characters
- Type: #\space ; ==> “space”
- Judgement: function: char?
- Operation: char=? char<? char>? char<=? char>=? char-ci=? char-ci<? char-downcase char-upcase
Symbols $\Delta$
- Type: quote, ‘, define
- Judgment: symbol?
- Operation: eqv? (eqv? ‘Calorie ‘calorie) ==> #t; set!
1 | (set! 'xyz 9) ; (define xyz 9) |
复合数据类型
通过组合其他数据结构的方式获得
Strings
1 | "Hello, World!" |
- Type: “”, string
- Judgment: string?
- Operation: string-ref; string-append; make-string; string-set!
1 | (string-ref "Hello" 0) |
Vectors
Vectors的元素可以是任何类型
- Type: (vector …)
- Judgment: vector?
- Operation: make-vector
1 | (vector 0 1 2 3 4) |
Dotted pairs and List
- Dotted pair
1 | (cons 1 #t) |
点对不能自运算,因此在使用值创建时必须使用以下方式:
1 | '(1 . #t) |
类似于C的指针
- Type: (cons a b) ‘(a . b)
- Judgment: pair?
- Operation: set-car! set-cdr! car cdr (支持四级操作)
- List
- Type: (list a b c …)
- Judgment: list?
- Operation:
数据类型转换
1 | char->integer |
其他数据类型
- procedure
- port: 例如,使用display时,默认将控制台作为输出端口
S表达式 $\Delat$
所有的Lisp和类Lisp语言,在表达数据结构时,都使用S表达式的形式
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 ZuowangDev's Blog!