mes.c: implement string->list.
This commit is contained in:
parent
00e000306d
commit
ec8553dc4f
5
mes.c
5
mes.c
|
@ -1160,9 +1160,10 @@ readstring ()
|
|||
int c = getchar ();
|
||||
while (true) {
|
||||
if (c == '"') break;
|
||||
*p++ = c;
|
||||
if (c == '\\' && peek_char () == '"') *p++ = getchar ();
|
||||
if (c == EOF) assert (!"EOF in string");
|
||||
else if (c == '\\' && peek_char () == 'n') {getchar (); *p++ = '\n';}
|
||||
else if (c == EOF) assert (!"EOF in string");
|
||||
else *p++ = c;
|
||||
c = getchar ();
|
||||
}
|
||||
*p = 0;
|
||||
|
|
6
scm.mes
6
scm.mes
|
@ -58,6 +58,12 @@
|
|||
(if (= 0 n) '()
|
||||
(cons fill (loop (- n 1)))))))
|
||||
|
||||
(define (string->list s)
|
||||
(let ((n (string-length s)))
|
||||
(let loop ((i 0))
|
||||
(if (= i n) '()
|
||||
(cons (string-ref s i) (loop (+ i 1)))))))
|
||||
|
||||
(define (vector . rest) (list->vector rest))
|
||||
(define (make-vector n . x)
|
||||
(list->vector (apply make-list (cons n x))))
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
(pass-if "string-ref" (seq? (string-ref "hello world" 4) #\o))
|
||||
(pass-if "eq?" (not (eq? (string-append "a" "b" "c") "abc")))
|
||||
(pass-if "string-length" (seq? (string-length (string-append "a" "b" "c")) 3))
|
||||
(pass-if "string->list" (sequal? (string->list "abc\n") '(#\a #\b #\c #\newline)))
|
||||
(pass-if "char" (seq? (char->integer #\A) 65))
|
||||
(pass-if "char 2" (seq? (char->integer #\101) (char->integer #\A)))
|
||||
(pass-if "char 3" (seq? (integer->char 10) #\newline))
|
||||
|
|
Loading…
Reference in a new issue