Hello users,

I would like to read lines from a file, process each line
and return either the success of the operation or the processed line to another function located in another module.

Below are two functions that work OK, but are in my opinion "ugly" because they use "set!".

It there a way to make both functions work without "set!"?


;;------------------------------------------------------------
(define (read-on-row *params*)
;; Returns the last line in "myfile" which contains
;; substring "ON", otherwise #f

  (define pdata #f) ;; I do not like this extra variable!

  (call-with-input-file (hash-ref *params* "myfile")
    (lambda (inp)
      (for/last ([row (in-lines inp 'return-linefeed)]
                 #:when (string-contains? "ON" row))
        (set! pdata row))))

  pdata)

;;------------------------------------------------------------

(define (on-row-exists *params*)
;; Returns #t if there is line in "myfile" which contains
;; substring "ON", otherwise #f

  (define found-on #f) ;; I do not like this extra variable!

  (call-with-input-file (hash-ref *params* "myfile")
    (lambda (inp)
      (for/last ([row (in-lines inp 'return-linefeed)]
                 #:when (string-contains? "ON" row))
        (set! found-on #t))))

  found-on)

-pekka-


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to