boot2

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

062-list-ref.scm (719B)


      1 ; (list-ref xs n) -- 0-indexed nth element. Out-of-range is undefined
      2 ; behavior (consistent with car/cdr policy); we only test the in-range
      3 ; cases here.
      4 
      5 (define xs '(a b c d e))
      6 
      7 (if (eq? (list-ref xs 0) 'a) 0 (sys-exit 1))
      8 (if (eq? (list-ref xs 1) 'b) 0 (sys-exit 2))
      9 (if (eq? (list-ref xs 4) 'e) 0 (sys-exit 3))
     10 
     11 ; Mixed types.
     12 (define ys (list 1 "two" 'three '(4 5)))
     13 (if (= (list-ref ys 0) 1) 0 (sys-exit 4))
     14 (if (bytevector=? (list-ref ys 1) "two") 0 (sys-exit 5))
     15 (if (eq? (list-ref ys 2) 'three) 0 (sys-exit 6))
     16 (if (equal? (list-ref ys 3) '(4 5)) 0 (sys-exit 7))
     17 
     18 ; Independently of `length` (don't entangle the tests).
     19 (if (= (list-ref (cons 10 (cons 20 (cons 30 '()))) 2) 30) 0 (sys-exit 8))
     20 
     21 (sys-exit 0)