The data in Scheme is very rich! In general, it is two kinds, one is a simple data type, one is a composite data type. In the simple data type, there is also a logical, numerical, character type, and symbol type. Complex data types contain string, vector type, dot pair, and list type. These are briefly described below.
1: Logical
This is nothing to say, as a true and false problem, the corresponding value is #T, #f, please and the true, false in C . Boolean? This process can test whether the parameters are logical.
(
Boolean? #t) => #t
(
Boolean? #f) => #t
NOT this process, and seeking logic is very similar
(not #f) => #t
Note that these two examples, the parameters of the coupon are logical, as a special case, if the parameter is not logical, but other types of data, what will be?
(Boolean? "Hello, World")
(Not "Hello, World")
(Boolean? 1)
(Not 1)
By running, it is known that these four statements, the return is #f, so it is understood that as long as the parameters of these two processes are not logical, they are returned.
2: Value
Numeric, including integers (32), score (3/5), real (1.234), plural (3 2i)
NUMBER? Test is a numeric value, complex? Test is a plurality of reusing type, REAL? Test is a real number, Rational? Test is score, Integer? Test is an integer
(NUMBER? 32) => #t
(Number? 1/3) => #t
(Number? 2 3i) => #t
(Number? 1.111) => #t
(Number? "Hello, World") => #f
(COMPLEX? 1 2i) => #t
(REAL? 2 3i) => #f
(REAL? 3.1416) => #t
(REAL? 22/7) => #t
(REAL? 42) => #t
(Rational? 2 3i) => #f
(Rational? 3.1416) => #t
(Rational? 22/7) => #t
(Integer? 22/7) => #f
(Integer? 42) => #t
Scheme's integer, not necessarily if it is decomposed, can also be used to identify binary (#b), octal (#o), hexadecimal (#h) and optional decix (#d), such as # B1111, # O17, # HF, # D15 are all 15 in decimal decimal.
Integer comparison operation EQV? Compare two integers equal (EQV? 11 12) Of course, you can use = instead, such as (= 11 12) and the above statement is equivalent, and <, <=, >,> =
(<1 2) => #t
(> 1 2) => #f (<= 1 2) => # t
(> = 1 2) => # f
About integer calculation , -, *, /, expt
( 1 2 3) => 6
(- 5.3 2) => 3.3
(- 5 2 1) => 2
(* 1 2 3) => 6
(/ 6 3) => 2
(/ 22 7) => 22/7
(exPt 2 3) => 8
(exPt 4 1/2) => 2.0
Single-grade operations about -, /
(- 1) => -1
(/ 4) => 1/4
Maximum, minimum max, min
(MAX 1 2 3 4 5) => 5
(MIN 1 2 3 4 5) => 1
Just absolute absolute ABS, 3: character type character, prefix # / start, such as # / c, # / b is C, B characters, non-print characters, can add names after the prefix, such as # / newline, # / TAB, # / space Characters The comparison predicate: char =?, char?, char> = ?.
(CHAR =? # / a # / a) => #t
(char? # / a) #t
(CHAR> =? # / a # / b) => #f
If you want it to be insensitive to case, you can use CHAR-CI instead of char, such as
(CHAR-CI =? # / a # / a) => #t
Size characters conversion char-downcase and char-upcase
4: Symbol type
Oh, this symbol name, some similar enumeration type, is a name, do not need to use his numerical meaning, just need this symbol, which is the meaning of the name. For example, RED, Blue, even don't need to know how much his Red, Blue is specifically, just know that Red represents red, and Blue represents blue enough to define quote to define (quote red) of course This is very frequent, for simplicity, there is a simple definition, that is, add a 'BLUE to introduce several procedures for symbol type SYMBOL? Test whether it is a symbol type, EQV? Test two symbol type values Whether it is equal, pay attention, this is not distinguished.
(Symbol 'Red) => #t
(Symbol 123) => #f
(EQV? 'red' red) => #t
(EQV? 'red' blue) => #f
You can use define to define a global variable (Define ABC 9), use set! To change the defined value, pay attention to change the data type, such as
(Define ABC 9) ABC => 9
(set! ABC # / c) ABC => # / c
5: String
This doesn't have to say more, it is necessary to explain that it is a string that caused by double quotes.
"Hello" => "Hello"
Below, it is necessary to explain the process / function string used in the string, this function can be bound to strings.
(String # / O) => "Hello" string-ref, extract specific characters in strings, strings start counting from 0
(Define Hello "Hello, World")
(String-Ref Hello 0) => # / h
String-append puts a string to another string
(String-append "hello" "world") => "Hello World"
6: Vector vector is a sequence, such as a string is also a sequence, but the elements type of vector is arbitrary
(Vector 12 "Hello" # / c) => # 3
(12 "Hello" # / c)
7: Point
Point pair, is a combination of two arbitrary order values. The first element is called Car, the second element is called CDR
(Define X (cons 1 #t))
(car x) => 1
(CDR X) => #t