boot2

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

061-length.scm (648B)


      1 ; (length xs) -- count of pairs in a proper list. Behavior on improper
      2 ; / circular lists is unspecified; we just check the proper-list cases
      3 ; that LISP.md commits to.
      4 
      5 (if (= (length '()) 0) 0 (sys-exit 1))
      6 (if (= (length '(a)) 1) 0 (sys-exit 2))
      7 (if (= (length '(a b c d e)) 5) 0 (sys-exit 3))
      8 (if (= (length (cons 1 (cons 2 (cons 3 '())))) 3) 0 (sys-exit 4))
      9 
     10 ; Same length, different element types.
     11 (if (= (length (list 1 'two "three" '(4))) 4) 0 (sys-exit 5))
     12 
     13 ; Built dynamically.
     14 (define (range n)
     15   (let loop ((i 0) (acc '()))
     16     (if (= i n) acc (loop (+ i 1) (cons i acc)))))
     17 (if (= (length (range 17)) 17) 0 (sys-exit 6))
     18 
     19 (sys-exit 0)