-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
76 lines (51 loc) · 1.8 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Chap 4:
Lists, Arrays - vectors & strings , Structures, Hash Tables
Instance.
Make the array:
(make-array
'(2 3) ; Dimensions of the array
:initial-element nil) ; Element to be filled by default.
Retrieve an element:
(aref arr 0 0)
setf works the normal way
Literal way to denote arrays is #na where n is the number of dimensions
#2a((b nil nil) (nil nil nil))
If *print-array* is t then an array will always be printed in the above form.
For 1D array
(setf vec (make-array 4 :initial-element nil))
#(nil nil nil nil)
1D Array == Vector
(vector "a" 'b 3)
#("a" B 3)
Use the above syntax to denote a literal vector.
aref can be used, but svref is faster
(svref vec 0)
STRINGS - Are vectors of characters.
constant strings are "series of characters surrounded by double quotes"
individual characters - #\c
char-code & code-char
aref will work on strings, but char is faster
(aref "afroz" 1) OR (char "afroz" 1)
setf works as usual for strings.
Calling format with |nil| as the first argument makes it return as a string what it would have printed.
(format nil "~A or ~A" "truth" "dare")
Sequence includes lists and vectors (and therefore strings)
Sequence
|
-----------------------
| |
array list
|
vector
|
strings
Functions Learned:
make-array - make the array
aref - reference an element of the array
vector - make a vector
svref - reference an element of the vector
char-code - character to number
code-char - number to character
char<, char<=, char>, char>=, char/= - comparison functions on characters
string-equal - ignores case
concatenate - concatenates 'stuff' (concatenate 'string "not " "to worry")