summaryrefslogtreecommitdiff
path: root/chapter22
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-04-23 14:02:44 -0700
committerCliff Click <cliffc@acm.org>2025-04-23 14:02:44 -0700
commitcbe707b67f1c8b8ce0fe91427596109f2f4179ee (patch)
treeb088932b046032e91381573d5ac2d909da3cb8d6 /chapter22
parent1b828fb177f7d595d937ec760fe68fe49c4301f0 (diff)
downloadSimple-cbe707b67f1c8b8ce0fe91427596109f2f4179ee.tar.gz
Simple-cbe707b67f1c8b8ce0fe91427596109f2f4179ee.zip
Update README.md
Diffstat (limited to 'chapter22')
-rw-r--r--chapter22/README.md21
1 files changed, 14 insertions, 7 deletions
diff --git a/chapter22/README.md b/chapter22/README.md
index 99bb7563..42deed69 100644
--- a/chapter22/README.md
+++ b/chapter22/README.md
@@ -224,10 +224,12 @@ struct str {
for( int i=0; i<len; i++ )
v2[i] = [i];
v2.len = len;
- sys.libc.free(this);
+ sys.libc.free(this); // Needs a better Mem Management solution
return v2;
}
+ val print { -> sys.libc.write(1/*stdout*/,[]/*array base as argument to C*/,len); return this; }
+
u32 len; // In-use size
u32 #; // Max length is 4Gig, although variants can request smaller lengths
u8 []; // Character data
@@ -235,9 +237,6 @@ struct str {
```
-
-
-
### A Final String
Intended to be a **immutable** string, possibly used as a base for a **secure**
@@ -246,12 +245,20 @@ defensive copy.
```java
struct sstr {
- //
+ // Possible static call syntax; no references to "this"
+ val make { str str -> new sstr[str#,str.at] };
+
+ // Array contents are immutable.
+ // Still figuring out good syntax for this.
u8 #;
- u8 [];
+ u8 []!; // Trailing '!'? Makes primitive array contents *immutable* and requires constructor syntax
};
-```
+// Construction requires a function that produces the array contents.
+// Here we are defining a defensive copy over `buf`.
+sstr safe = new sstr[buf.len,{ int idx -> buf[idx]; }];
+sstr safe = sstr.make("abc"); // Defensive copy is made
+```
### A Extendable String (aka StringBuilder or StringBuffer)