boot2

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

095-unless.scm (993B)


      1 ; (unless test body...) -- mirror of `when`. Body runs (and last value
      2 ; is returned) when test is #f; otherwise UNSPEC.
      3 
      4 ;; --- Falsy test: body runs, last form is the value -------------------
      5 (if (= 5 (unless #f 1 2 3 4 5)) 0 (sys-exit 1))
      6 
      7 ;; --- Truthy test: body skipped; result is UNSPEC ---------------------
      8 (if (eq? (unless #t (sys-exit 99)) (unless 0 42)) 0 (sys-exit 2))
      9 (if (not (eq? (unless #t 1) #t))  0 (sys-exit 3))
     10 (if (not (eq? (unless #t 1) #f))  0 (sys-exit 4))
     11 (if (not (eq? (unless #t 1) '())) 0 (sys-exit 5))
     12 
     13 ;; --- Body side-effects fire only when test is falsy ------------------
     14 (define counter 0)
     15 (unless #t (set! counter 100))
     16 (if (= counter 0) 0 (sys-exit 6))
     17 (unless #f (set! counter (+ counter 1)) (set! counter (+ counter 2)))
     18 (if (= counter 3) 0 (sys-exit 7))
     19 
     20 ;; --- Any non-#f counts as true (so body is skipped) ------------------
     21 (if (eq? (unless 0  1) (unless #t 1)) 0 (sys-exit 8))
     22 (if (eq? (unless '() 1) (unless #t 1)) 0 (sys-exit 9))
     23 
     24 (sys-exit 17)