Fix core:car, core:cdr for specials.
* mes.c (car_, cdr_): Return special. Fixes string->list, returning nil. * tests/scm.test ("string-length", "string->list"): New tests.
This commit is contained in:
parent
9848c90738
commit
3dd219b891
2
mes.c
2
mes.c
|
@ -246,6 +246,7 @@ car_ (SCM x)
|
|||
{
|
||||
return (TYPE (CAR (x)) == PAIR
|
||||
|| TYPE (CAR (x)) == REF
|
||||
|| TYPE (CAR (x)) == SPECIAL
|
||||
|| TYPE (CAR (x)) == SYMBOL
|
||||
|| TYPE (CAR (x)) == STRING) ? CAR (x) : MAKE_NUMBER (CAR (x));
|
||||
}
|
||||
|
@ -255,6 +256,7 @@ cdr_ (SCM x)
|
|||
{
|
||||
return (TYPE (CDR (x)) == PAIR
|
||||
|| TYPE (CDR (x)) == REF
|
||||
|| TYPE (CAR (x)) == SPECIAL
|
||||
|| TYPE (CDR (x)) == SYMBOL
|
||||
|| TYPE (CDR (x)) == STRING) ? CDR (x) : MAKE_NUMBER (CDR (x));
|
||||
}
|
||||
|
|
|
@ -68,13 +68,24 @@ exit $?
|
|||
(pass-if "=" (seq? 3 '3))
|
||||
(pass-if "= 2" (not (= 3 '4)))
|
||||
|
||||
(pass-if-equal "string-length"
|
||||
0
|
||||
(string-length ""))
|
||||
(pass-if-equal "string-length 2"
|
||||
3
|
||||
(string-length (string-append "a" "b" "c")))
|
||||
(pass-if-equal "string->list"
|
||||
'()
|
||||
(string->list ""))
|
||||
(pass-if-equal "string->list 2"
|
||||
'(#\a #\b #\c #\newline)
|
||||
(string->list "abc\n"))
|
||||
|
||||
(pass-if "string-append" (sequal? (string-append "a" "b" "c") "abc"))
|
||||
(pass-if "substring" (sequal? (substring "hello world" 6) "world"))
|
||||
(pass-if "substring 2" (sequal? (substring "hello world" 4 7) "o w"))
|
||||
(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-equal "string->list" '(#\a #\b #\c #\newline) (string->list "abc\n"))
|
||||
(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