[plt-scheme] iterate over characters in string
ptg at ccs.neu.edu writes:
> Chris, here's a fairly non-verbose version:
>
> ; : str -> nat
> (define (checksum line)
> (modulo (apply + (map char->integer (string->list line))) 256))
Very nice! (in terms of verbosity)
> For practice, see if you can write one using the foldl function instead
> of map and apply.
I'll look into that.
> If the intermediate list bothers you, either look up
> string-ref, or implement a deforestation compiler pass for mzscheme :-)
The "deforestation" compiler pass is a term I've never heard, but I
assume you mean to write an mzscheme extension that does this? That
was what I was thinking would be necessary unless it had already been
done, in which case I'd rather not re-invent the wheel.
> The best way to good performance is to implement a handful of versions
> and benchmark them. DrScheme's profiler will help.
I've just made the move to v200 from 1.03. I'm looking forward to
using the profiler.
--
Chris