One thing I was confused about when I first started using Julia was that things that are done with strings in other languages are often done directly with IO objects in Julia.
For example, consider that, in Python, most classes define `__str__()` and `__repr__()`, which create string representations of objects of this class (the first more meant for human consumption, the second for parsing (usually)). In Julia, the implicit assumption is that most strings are meant for output in some way, so why not skip the extra memory allocation and write the string representation directly to output. For this, types define `show(io::IO, x::MyType)`. If you really want to manipulate such strings, you can (as pointed out in this thread) go through an IOBuffer object first. (There is also `repr(x::SomeType)`, but it's not emphasized as much.) This was a design decision made early on. I personally found (and still find) it somewhat awkward at times, but for many things, it works fine, and (seemingly) it lets most string output allocate less memory by default. Now, it certainly is the case that mutable strings may be very useful in some contexts. The BioSeq.jl package implements mutable DNA and protein sequences, which are very useful there, and would be represented by mutable strings in many other languages. The best way to test that would probably be to create a package (say, MutableStrings.jl), and define useful types and functions there. Cheers, Kevin On Sun, May 3, 2015 at 12:20 PM, Tamas Papp <[email protected]> wrote: > consider > > let io = IOBuffer() > write(io,rand(10)) > takebuf_array(io) > end > > IOBuffer() is not specific to strings at all. > > Best, > > Tamas > > On Sun, May 03 2015, Scott Jones <[email protected]> wrote: > > > Because you can have binary strings and text strings... there is even a > > special literal for binary strings... > > b"\xffThis is a binary\x01\string" > > "This is a \u307 text string" > > > > Calling it an IOBuffer makes it sound like it is specific to I/O, not > just > > strings (binary or text) that you might never do I/O on... > > > > On Sunday, May 3, 2015 at 2:43:14 PM UTC-4, Kristoffer Carlsson wrote: > >> > >> Why should it be called StringBuffer when another common use of it is to > >> write raw binary data? >
