简单数据类型

  • 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
2
3
4
5
6
7
(eqv? 42 42) ; ==> #t
(eqv? 42 42.0) ; ==> #f
(/ 2) ; ==> 1/2
(- 2) ; ==> -2
(max 1 2 1 4 2) ; ==> 4
(min 1 2 3 1 4) ; ==> 1
(abs -4) ; ==> 4

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
2
3
4
"Hello, World!"
; ==> "Hello, World!"
(string #\h #\e #\l #\l #\o)
; ==> "hello"
  • Type: “”, string
  • Judgment: string?
  • Operation: string-ref; string-append; make-string; string-set!
1
2
3
4
5
6
7
(string-ref "Hello" 0)
; ==> #\H
(string-append "E " "Pluribus " "Unum")
; ==> "E Pluribus Unum"
(define a_e_char_long_string (make-string 3))
(string-set! "hello" 1 #\a)
; ==> hallo

Vectors

Vectors的元素可以是任何类型

  • Type: (vector …)
  • Judgment: vector?
  • Operation: make-vector
1
2
3
(vector 0 1 2 3 4)
; ==> #(0 1 2 3 4)
(define v (make-vector 5))

Dotted pairs and List

  1. Dotted pair
1
2
(cons 1 #t)
; ==> (1 . #t)

点对不能自运算,因此在使用值创建时必须使用以下方式:

1
2
'(1 . #t)
; ==> (1 . #t)

类似于C的指针

  • Type: (cons a b) ‘(a . b)
  • Judgment: pair?
  • Operation: set-car! set-cdr! car cdr (支持四级操作)
  1. List
  • Type: (list a b c …)
  • Judgment: list?
  • Operation:

数据类型转换

1
2
3
4
5
char->integer
integer->char
string->list
string->number
symbol->string

其他数据类型

  1. procedure
  2. port: 例如,使用display时,默认将控制台作为输出端口

S表达式 $\Delat$

所有的Lisp和类Lisp语言,在表达数据结构时,都使用S表达式的形式