-
-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change return type of String.add to String iso^
Fixes #3750 by implementing RFC 69.
- Loading branch information
1 parent
b9c890f
commit fc688c8
Showing
4 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## Change the return type of String.add to String iso^ (RFC 69) | ||
|
||
This release introduces a breaking change by changing the return type of `String.add` from `String val` to `String iso^`. | ||
|
||
Where you previously had code like: | ||
|
||
```pony | ||
let c = Circle | ||
let str = "Radius: " + c.get_radius().string() + "\n" | ||
env.out.print(str) | ||
``` | ||
|
||
you now need: | ||
|
||
```pony | ||
let c = Circle | ||
let str = recover val "Radius: " + c.get_radius().string() + "\n" end | ||
env.out.print(str) | ||
``` | ||
|
||
or you can also let the compiler do the work for you by using explicit type declarations: | ||
|
||
```pony | ||
let c = Circle | ||
let str: String = "Radius: " + c.get_radius().string() + "\n" | ||
env.out.print(str) | ||
``` | ||
|
||
The above code works since `val` is the default reference capability of the `String` type. | ||
|
||
The new type makes it simpler to implement the `Stringable` interface by using `String.add`. Where before you had code like: | ||
|
||
```pony | ||
class MyClass is Stringable | ||
let var1: String = "hello" | ||
let var2: String = " world" | ||
fun string(): String iso^ => | ||
recover | ||
String.create(var1.size() + var1.size()) | ||
.>append(var1) | ||
.>append(var2) | ||
end | ||
``` | ||
|
||
you can now implement the `string` method as such: | ||
|
||
```pony | ||
class MyClass is Stringable | ||
let var1: String = "hello" | ||
let var2: String = " world" | ||
fun string(): String iso^ => | ||
var1 + var2 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters