boot2

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

060-set-pair-bang.scm (650B)


      1 ; (set-car! pair val) and (set-cdr! pair val) -- in-place pair mutation.
      2 ; Both return unspecified; the visible effect is via car/cdr.
      3 
      4 (define p (cons 1 2))
      5 (set-car! p 10)
      6 (if (= (car p) 10) 0 (sys-exit 1))
      7 (if (= (cdr p) 2)  0 (sys-exit 2))
      8 
      9 (set-cdr! p 20)
     10 (if (= (car p) 10) 0 (sys-exit 3))
     11 (if (= (cdr p) 20) 0 (sys-exit 4))
     12 
     13 ; Mutation visible through aliases.
     14 (define q p)
     15 (set-car! q 99)
     16 (if (= (car p) 99) 0 (sys-exit 5))
     17 
     18 ; cdr can be a non-pair, a pair, or '().
     19 (set-cdr! p (cons 7 '()))
     20 (if (= (car (cdr p)) 7) 0 (sys-exit 6))
     21 (if (null? (cdr (cdr p))) 0 (sys-exit 7))
     22 
     23 (set-cdr! p '())
     24 (if (null? (cdr p)) 0 (sys-exit 8))
     25 
     26 (sys-exit 0)