104-single-arm-if.scm (892B)
1 ; (if test then) -- single-arm if. When test is non-#f, evaluates and 2 ; returns then. When test is #f, returns UNSPEC instead of segfaulting 3 ; off the missing else slot. 4 5 ;; --- Truthy: returns then ------------------------------------------------ 6 (if (= 9 (if #t 9)) 0 (sys-exit 1)) 7 (if (= 9 (if 0 9)) 0 (sys-exit 2)) 8 (if (= 9 (if '() 9)) 0 (sys-exit 3)) 9 10 ;; --- Falsy: returns UNSPEC (singleton, eq? to other UNSPECs) ------------ 11 (if (eq? (if #f 9) (if #f 7)) 0 (sys-exit 4)) 12 (if (not (eq? (if #f 9) #t)) 0 (sys-exit 5)) 13 (if (not (eq? (if #f 9) #f)) 0 (sys-exit 6)) 14 (if (not (eq? (if #f 9) '())) 0 (sys-exit 7)) 15 (if (not (eq? (if #f 9) 0)) 0 (sys-exit 8)) 16 17 ;; --- Side effects: then runs only on truthy ------------------------------ 18 (define counter 0) 19 (if #f (set! counter 100)) 20 (if (= counter 0) 0 (sys-exit 9)) 21 (if #t (set! counter 5)) 22 (if (= counter 5) 0 (sys-exit 10)) 23 24 (sys-exit 42)