Created
April 30, 2010 20:45
-
-
Save cametan001/385725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CL-USER> (segment-reader t #\/ 3) | |
あいう/えおか/きくけ/ | |
("あいう" "えおか" "きくけ") | |
CL-USER> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; SEGMENT-READER with DO | |
(defun segment-reader (stream ch n) | |
(do ((n n (1- n)) | |
(acc nil | |
(push | |
(do ((curr (read-char stream) | |
(read-char stream)) | |
(chars nil (push curr chars))) | |
((char= ch curr) (coerce (nreverse chars) 'string))) | |
acc))) | |
((< n 1) (nreverse acc)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; SEGMENT-READER | |
;; Scheme-style | |
(defun segment-reader (stream ch n &optional (acc nil)) | |
(labels ((iter (chars curr) | |
(if (char= ch curr) | |
(coerce (reverse chars) 'string) | |
(iter (cons curr chars) (read-char stream))))) | |
(if (< n 1) | |
(reverse acc) | |
(segment-reader stream ch (1- n) | |
(cons (iter nil (read-char stream)) acc))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment