[racket] help me speed up string split?

From: Sam Tobin-Hochstadt (samth at cs.indiana.edu)
Date: Wed Jun 18 19:45:55 EDT 2014

On Wed, Jun 18, 2014 at 7:33 PM, Ryan Davis <zenspider at gmail.com> wrote:
>
> 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)))))


Right, `in-port`s implementation is basically the `eof-object?` test
that you have there. `port->list` works best when you already have a
function that you want which has the signature of `read`.

I don't think there's a way to write a version of `port->list` that's
as clean as you'd like it to be here, sadly.

Sam


Posted on the users mailing list.