Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Programming Guide: further explanation about asMutable needed #233

Closed
ohookins opened this Issue · 4 comments

3 participants

@ohookins

In the programming guide, you correctly mention that asMutable is required to make a copy of an immutable symbol before you can apply operators such as strip.

However just a few lines later, examples are given with asUppercase and asLowercase that appear to violate the immutability. It would be nice if you clarified which operators attempt to alter existing objects and which operate on a copy of that immutable object (although arguably the behaviour itself is fairly opaque - at least in Ruby for example you have methods with and without a bang to identify which of these two scenarios is taking place).

@stevedekorte

The "as" prefix means, by convention, that a new instance is returned. It's like the sigil in Ruby but human readable.

@ohookins

I couldn't find documentation of that convention in the programming guide. Is that an appropriate place to put it?

@stevedekorte

Yes, sorry for the state of the documentation.

@mig-hub

I remember asking myself the same question but ended up thinking (maybe naively) that you need asMutable because any transformation can affect the length of the Sequence. So you need to transfer the Sequence on a growing buffer (mutable). But changing the case can be done in-place on the same memory location because it has the same length.

I might be wrong though.

@stevedekorte stevedekorte closed this in #234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.