[racket] Super basic question about strings

From: Richard Lawrence (richard.lawrence at berkeley.edu)
Date: Wed Nov 17 11:18:34 EST 2010

Neil Van Dyke <neil at neilvandyke.org> writes:

> For new students, I would show them examples like Eli and Matthias
> did.  For production work, I usually build up strings using string
> ports.
> Compared to various ways of building lists and doing "string-append",
> or to simply doing lots of incremental "string-append" or "format",
> using a string port usually permits more tail calls, and sometimes
> reduces allocations or otherwise inefficient calls.  (Note that I
> assume that the string port implementation itself is very efficient
> internally.)

Thanks, Neil.  This goes a bit more to the core of my question.  I have
become used to thinking of string formatting, joining, and concatenation
as "cheap" operations, and anything that looks like doing I/O as
"expensive."  But maybe that's not the right way to think about it, as
your example shows.  I shall do some incantations: "A string port is not
a file..."

Still, I am not currently in a position where performance matters that
much, so I will stick with "format" and friends for now.  It's nice to
know that ports are the right thing to grow up into, though.


Posted on the users mailing list.