File tree 4 files changed +33
-9
lines changed
4 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ With [Ultralisp](https://ultralisp.org/) installed:
22
22
Convert a string to a rope with ` make-rope ` , and turn it back into a
23
23
string with ` write-rope ` passing ` nil ` as the output.
24
24
25
+ You can also pass an input stream or pathname to ` make-rope ` to
26
+ efficiently read files.
27
+
25
28
``` lisp
26
29
(let* ((rope (rope:make-rope "Immutable Ropes for Common Lisp"))
27
30
(super (rope:insert-rope rope 10 "Super "))
@@ -32,7 +35,7 @@ string with `write-rope` passing `nil` as the output.
32
35
(rope:write-rope superer nil)))
33
36
```
34
37
35
- Split a rope at an index
38
+ Split a rope at an index:
36
39
37
40
``` lisp
38
41
(let ((rope (rope:make-rope "Immutable Super Ropes for Common Lisp")))
@@ -56,6 +59,21 @@ Concatenate ropes together:
56
59
57
60
![ Concatenated Rope] ( screenshots/concat.png )
58
61
62
+ Kill a segment of a rope:
63
+
64
+ ``` lisp
65
+ (let ((rope (rope:make-rope "Immutable Ropes for Common Lisp")))
66
+ (rope:write-rope (rope:kill-rope rope 20 27) t))
67
+ ```
68
+
69
+ Get chars or strings at a position:
70
+
71
+ ``` lisp
72
+ (let ((rope (rope:make-rope "Immutable Ropes for Common Lisp")))
73
+ (print (rope:index-rope rope 2))
74
+ (print (rope:substr-rope rope 10 15)))
75
+ ```
76
+
59
77
# Dev Utils
60
78
61
79
If you want to generate graphs as shown above, you will need to
Original file line number Diff line number Diff line change 3
3
(:export
4
4
# :rope ; CLASS
5
5
# :rope-length ; ACCESSOR
6
- # :rope-depth ; ACCESSOR
7
- # :branch ; CLASS
8
- # :branch-left ; ACCESSOR
9
- # :branch-right ; ACCESSOR
10
- # :leaf ; CLASS
11
- # :leaf-string ; ACCESSOR
12
6
# :make-rope ; CONSTRUCTOR
13
7
# :write-rope ; FUNCTION
14
8
# :prepend-rope ; FUNCTION
15
9
# :append-rope ; FUNCTION
16
10
# :insert-rope ; FUNCTION
17
11
# :index-rope ; FUNCTION
12
+ # :substr-rope ; FUNCTION
18
13
# :concat-rope ; FUNCTION
19
14
# :split-rope ; FUNCTION
20
15
# :kill-rope ; FUNCTION
Original file line number Diff line number Diff line change 180
180
(index-rope (branch-left rope) index)
181
181
(index-rope (branch-right rope) (- index weight))))))
182
182
183
+ (defun substr-rope (rope from &optional to)
184
+ " Get a substring out of a rope."
185
+ (multiple-value-bind (ante _) (split-rope rope (or to (rope-length rope)))
186
+ (declare (ignore _))
187
+ (multiple-value-bind (_ post) (split-rope ante from)
188
+ (declare (ignore _))
189
+ (write-rope post nil ))))
190
+
183
191
; ;--------;;
184
192
; ; Concat ;;
185
193
; ;--------;;
Original file line number Diff line number Diff line change @@ -41,10 +41,13 @@ can be done efficiently.")
41
41
(is (string= " Hello, super rope!" (rope :write-rope super nil )))))
42
42
43
43
(deftest index-rope ()
44
- " Test accessing characters by index"
44
+ " Test accessing characters and strings by index"
45
45
(let* ((rope (rope :make-rope " 0123456789" )))
46
46
(is (string= #\1 (rope :index-rope rope 1 )))
47
- (is (string= #\9 (rope :index-rope rope 9 )))))
47
+ (is (string= #\9 (rope :index-rope rope 9 ))))
48
+ (let ((rope (rope :make-rope " Immutable Ropes for Common Lisp" )))
49
+ (is (string= " Ropes" (rope :substr-rope rope 10 15 )))))
50
+
48
51
49
52
(deftest read-files-and-streams ()
50
53
" Test reading a file to a rope."
You can’t perform that action at this time.
0 commit comments