boot2

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

067-read-line.scm (778B)


      1 ; read-line splits on \n (consuming the newline). After the last line
      2 ; a follow-up read returns (#t . eof). This indirectly exercises
      3 ; bv-concat-reverse via the line-assembly path inside read-line.
      4 (define path "/tmp/scheme1-read-line.txt")
      5 (define op (open-output path))
      6 (if (not (car op)) (exit 10) 0)
      7 (write-bytes (cdr op) "alpha\nbeta\ngamma\n")
      8 (close (cdr op))
      9 
     10 (define ip (open-input path))
     11 (if (not (car ip)) (exit 20) 0)
     12 (define p (cdr ip))
     13 (define l1 (read-line p))
     14 (define l2 (read-line p))
     15 (define l3 (read-line p))
     16 (define l4 (read-line p))
     17 (close p)
     18 
     19 (if (and (car l1) (bytevector=? (cdr l1) "alpha")
     20          (car l2) (bytevector=? (cdr l2) "beta")
     21          (car l3) (bytevector=? (cdr l3) "gamma")
     22          (car l4) (eof? (cdr l4)))
     23     (exit 0)
     24     (exit 1))