Browse code
Fix split
Showing 2 changed files
... | ... |
@@ -238,6 +238,7 @@ |
238 | 238 |
(prog1 (list ,@(mapcar #'car result-binding)) |
239 | 239 |
,@body)))) |
240 | 240 |
|
241 |
+;; TODO: use multiple values . . . |
|
241 | 242 |
(defmacro prog1-let ((&rest result-binding) &body body) |
242 | 243 |
"Bind a bunch of symbols to values and return them via prog1" |
243 | 244 |
`(let (,@result-binding) |
... | ... |
@@ -158,15 +158,18 @@ |
158 | 158 |
(vector-push-extend (subseq string (+ pattern-length end-pos)) parts)) |
159 | 159 |
(return parts))))) |
160 | 160 |
|
161 |
-(defun split (divider string &key count (test nil)) |
|
161 |
+(defun split (divider string &key count (test nil) (type nil type-p)) |
|
162 | 162 |
(declare (optimize #+dev (debug 3) (speed 3) (space 3))) |
163 | 163 |
(unless test |
164 | 164 |
(setf test |
165 | 165 |
(typecase divider |
166 | 166 |
(string 'equal) |
167 | 167 |
(t 'eql)))) |
168 |
- (etypecase divider |
|
169 |
- (character (%split-on-char divider string :count count :test test)) |
|
170 |
- (string (if (= 1 (length divider)) |
|
171 |
- (%split-on-char (aref divider 0) string :count count :test test) |
|
172 |
- (%split-on-string divider string :count count :test test))))) |
|
168 |
+ (let ((result (etypecase divider |
|
169 |
+ (character (%split-on-char divider string :count count :test test)) |
|
170 |
+ (string (if (= 1 (length divider)) |
|
171 |
+ (%split-on-char (aref divider 0) string :count count :test test) |
|
172 |
+ (%split-on-string divider string :count count :test test)))))) |
|
173 |
+ (if type-p |
|
174 |
+ (coerce result type) |
|
175 |
+ result))) |