[racket] help me speed up string split?

From: Ryan Davis (zenspider at gmail.com)
Date: Wed Jun 18 19:33:01 EDT 2014

On Jun 18, 2014, at 15:55, Sam Tobin-Hochstadt <samth at cs.indiana.edu> wrote:

>> I'll stick to for/list + in-port + read
> 
> Note that this combination is nicely packaged up as `(port->list)`,
> and there's a couple optional arguments and also `file->list` for
> other versions of this.

ooh. I didn't find that last night. That's certainly cleaner (but if you want to use the default read) and looks to be exactly the same in performance. I think I prefer for/list + in-port because in-port doesn't hand me an eof, so the resulting handler is smaller:

(go (lambda ()
      (port->list (lambda (ip)
                    (define s (read-string 16 ip))
                    (if (eof-object? s)
                        s
                        (string->number (string-trim s)))))))

vs

(go (lambda ()
      (for/list ([s (in-port (curry read-string 16))])
        (string->number (string-trim s)))))




Posted on the users mailing list.