Welcome to the CHICKEN Scheme pasting service

file-select pasted by megane on Wed Dec 5 15:17:05 2018

(module
 hmh
 ()
 (import scheme)
 (cond-expand
  (chicken-5 (import (chicken base))
             (import (prefix (chicken file posix) posix:))
             (import (prefix (chicken process) posix:)))
  (else (import chicken)
        (use (only data-structures intersperse))
        (use (prefix posix posix:))))

 (define (p . args) (apply print (intersperse args " ")))
 (define log-info p)
 (define log-debug p)

 (define (foo)
   (receive (in-fd out-fd) (posix:create-pipe)
     (log-info "start test" in-fd out-fd)
     (let ([out-port (posix:open-output-file* out-fd #:append)]
           [in-port (posix:open-input-file* in-fd)])
       (log-debug "send")
       (display "1 " out-port)
       (display "2 " out-port)
       (display "3 " out-port)
       (log-debug "flush")
       (flush-output out-port)

       ;; (log-debug "close-output-port")
       ;; (close-output-port out-port)

       (receive (in-ready? _out-ready?) (posix:file-select in-fd #f 0)
         (print "in-ready? " in-ready?)
         (assert in-ready?))

       (define (equ? obj)
         (let ([o (read in-port)])
           (log-debug "read" o "exp:" obj)
           (assert (equal? obj o))))

       (equ? 1)
       (receive (in-ready? _out-ready?) (posix:file-select in-fd #f 0)
         (print "in-ready? " in-ready?)
         (assert in-ready?)
         ;; (unless in-ready?
         ;;   (print "not ready read:" (read in-port)))
         )
       (equ? 2)
       (equ? 3)

       (close-input-port in-port))
     (log-info "test OK")))

 (foo)

 )

strace for the select stuff added by C-Keen on Wed Dec 5 15:50:53 2018

fstat(4, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
write(1, "flush\n", 6flush
)                  = 6
write(4, "1 2 3 ", 6)                   = 6
poll([{fd=3, events=POLLIN}], 1, 0)     = 1 ([{fd=3, revents=POLLIN}])
write(1, "in-ready? 3\n", 12in-ready? 3
)           = 12
fstat(3, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
read(3, "1 2 3 ", 4096)                 = 6
write(1, "read 1 exp: 1\n", 14read 1 exp: 1
)         = 14
poll([{fd=3, events=POLLIN}], 1, 0)     = 0 (Timeout)
write(1, "in-ready? #f\n", 13in-ready? #f
)          = 13
write(2, "\nError", 6
Error)                  = 6
write(2, ": ", 2: )                       = 2
w

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the procedure to access a character in a string by index in R5RS?
Visually impaired? Let me spell it for you (wav file) download WAV