~tim/scheme-vm

fb7be1c50c0093ae060643761e439817e72eee77 — Tim Morgan 2 years ago f4525d8
Allow comparing more than 2 strings with string=?
2 files changed, 14 insertions(+), 5 deletions(-)

M lib/scheme/base.scm
M spec/lib/string-spec.scm
M lib/scheme/base.scm => lib/scheme/base.scm +11 -5
@@ 473,11 473,17 @@
                #f))
          #f))

    (define (string=? a b)
      (and
        (string? a)
        (string? b)
        (list=? (string->list a) (string->list b))))
    (define (string=? . strings)
      (if (< (length strings) 2)
        #t
        (let ((s1 (car strings))
              (s2 (cadr strings)))
          (if (and
                (string? s1)
                (string? s2)
                (list=? (string->list s1) (string->list s2)))
            (apply string=? (cdr strings))
            #f))))

    (define (pair=? a b) ; don't export this
      (if (equal? (car a) (car b))

M spec/lib/string-spec.scm => spec/lib/string-spec.scm +3 -0
@@ 13,8 13,11 @@
(assert (equal? '(#\f #\o #\o #\b #\a #\r #\b #\a #\z) (string->list "foobarbaz")))

(assert (string=? "foo" "foo"))
(assert (string=? "foo" "foo" "foo"))
(assert (not (string=? "foo" "foo" "baz")))
(assert (not (string=? "foo" "bar")))
(assert (not (string=? "foo" 1)))
(assert (not (string=? 1 1)))

(assert (equal? "" (string)))
(assert (equal? "a" (string #\a)))