I have the following code, which in sequence calls the load-file dialog,
loads the file, processes it and populates a textbox:

  (define (try v e)
    (if v (success v) (failure e)))

  (define (load-and-process-file textbox parse fmt)
      (define f #f)
      (let* [(text
              (do [fname <- (try (get-file) 'no-filename)]
                (define _ (set! f (some-system-path->string fname)))
                [contents <- (try (file->string fname) 'read-error)]
                [xw <- (try (parse contents) 'parse-error)]
                (try (fmt xw) 'format-error)))
             (status
              (either error-string
                      (λ (t) (begin (replace-text textbox t)
                                    "Loaded file ~a"))
                      text))]
        (and status (set-status (format status f)))))

I've resorted to set! to get the filename out of the do chain so I can
display it as part of the status, but that feels a bit hacky. Is there a
neater way to do it?

martin

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFrFfuGOnLMMCMfCN4HyMhWXV9OUQvQ-54xDrt4gEV7AV2JTiw%40mail.gmail.com.

Reply via email to