boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

057-bytevector-eq.scm (984B)


      1 ; (bytevector=? a b) -> #t iff a and b are bytevectors of equal length
      2 ; with the same bytes. Only structural; non-bytevector inputs are #f
      3 ; rather than an error (kept lax until LISP.md pins the policy).
      4 
      5 ; Self-equal.
      6 (if (bytevector=? "abc" "abc") 0 (sys-exit 1))
      7 
      8 ; Empty bytevectors.
      9 (if (bytevector=? "" "") 0 (sys-exit 2))
     10 
     11 ; Distinct identity, same bytes.
     12 (define a (make-bytevector 3 65))
     13 (define b (make-bytevector 3 65))
     14 (if (bytevector=? a b) 0 (sys-exit 3))
     15 
     16 ; Same length, differing byte.
     17 (bytevector-u8-set! b 1 66)
     18 (if (not (bytevector=? a b)) 0 (sys-exit 4))
     19 
     20 ; Different length (prefix match).
     21 (define c (make-bytevector 4 65))
     22 (if (not (bytevector=? a c)) 0 (sys-exit 5))
     23 
     24 ; String literal vs handcrafted bv with identical bytes.
     25 (define s "AAA")
     26 (if (bytevector=? s a) 0 (sys-exit 6))
     27 
     28 ; Non-bytevector inputs return #f rather than crashing.
     29 (if (not (bytevector=? '(1 2 3) "abc")) 0 (sys-exit 7))
     30 (if (not (bytevector=? "abc" 'foo)) 0 (sys-exit 8))
     31 
     32 (sys-exit 0)