The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

hanafey (18) [Avatar] Offline
Section 3.4.2 has a note "Placeholder evaluation time" that makes the reader wonder if the "values" and "strings" parts of a GString can be changed. Thinking "String", a reasonable guess is these properties will have read only access. The following examples shows that GStrings are mutable. Seems like this should be made clear at this point in the book.

def a = 'abc'
def b = 123
def c = "a is $a and b is $b"
println c
c.values[0] = 'foobar'
println c
c.strings[0] = 'It is no longer abc '
println c

a is abc and b is 123
a is foobar and b is 123
It is no longer abc foobar and b is 123
paulk_asert (33) [Avatar] Offline
Re: GStrings mutable of immutable?
Using placeholders that are Closures is part of the design of GStrings that allows the GString to change over time. Changing the underlying values or strings arrays happens to allow the GString also to change but isn't part of the conventions around how GStrings are normally used, rather an implementation detail that might change in the future so we tend not to promote its usage too much. We should though improve our description of this fact. Thanks for your suggestion.