Closed ghost closed 1 year ago
Correct, it is immutable. It can be changed to modify the contents of the caller, thoughts?
Correct, it is immutable. It can be changed to modify the contents of the caller, thoughts?
Please have a look at this code:
class Test1 {
function : Main(args : String[]) ~ Nil {
str := "foo";
str->Append("bar");
str->PrintLine();
}
}
If str->Append()
could change the value of str
, why can't str->Replace()
?
Let we recall the failed to compile pieces of code on https://github.com/objeck/objeck-lang/issues/250:
class Test1 {
function : Main(args : String[]) ~ Nil {
str := "foo";
(str + "bar")->PrintLine();
}
}
class Test1 {
function : Main(args : String[]) ~ Nil {
str := "foo";
str->Append("bar")->PrintLine();
}
}
Then have a look at this code:
class Test1 {
function : Main(args : String[]) ~ Nil {
str := "foo";
str->Replace("o", "a")->PrintLine();
}
}
Surprisingly, it compiled just fine.
So my opinion is, there is nothing special about str->Replace()
.
If str->Append()
doesn't return a new string, then so does str->Replace()
. If you want to make str->Replace()
return a new string, then you have to make str->Append()
return a new string too.
Try
str += "bar";
str->PrintLine();
Append is called for the +=
operator. I did not want it to return a new instance for performance reasons. Let me think more about your feedback.
Try
str += "bar"; str->PrintLine();
Append is called for the
+=
operator. I did not want it to return a new instance for performance reasons. Let me think more about your feedback.
Please don't misunderstand what I said. The only thing I said is that str->Replace()
is not any more special than other methods, so if str->Append()
doesn't return a new string, then str->Replace()
shouldn't either.
str->ReplaceAll()
shouldn't return a new string, too.
Thanks for the feedback. I break operations into two categories. The first is, operations that add to an existing string in a predictable manner, like stream concatenation. The second, operations that modify a buffer in a more dynamic manner such as substring replacement. Concatenation is a common operation used frequently to build strings. Operations that 'may' modify all the contents of an should be a mutable in my opinion.
Thanks for the feedback. I break operations into two categories. The first is, operations that add to an existing string in a predictable manner, like stream concatenation. The second, operations that modify a buffer in a more dynamic manner such as substring replacement. Concatenation is a common operation used frequently to build strings. Operations that 'may' modify all the contents of an should be a mutable in my opinion.
Any of what you said have been added to the document yet? I don't see any changes on Getting Started
. Btw, long story short, nothing changed?
For the last release, the focus was fixing the REPL shell. I will revisit the API documentation this iteration and record a few videos. The API docs will link to code examples and videos.
For Getting Started
, I added an example of how to iterate over a Map
's values.
Below are trial run videos. I need to link the related code with the videos.
I will also post-edit the "real" videos once I finish creating the pipeline.
Do you think this is useful?
It seems
String->Replace()
doesn't change the value of the string?For example:
Is it consistent with https://github.com/objeck/objeck-lang/issues/250?