about summary refs log tree commit diff stats
path: root/059to_text.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-09-15 13:46:13 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-09-15 14:04:22 -0700
commitb75d9d456cb36ad41ab735586473adbbf3444643 (patch)
tree4f3413a11bb93831e1e71d6a99d8bb1323de77d2 /059to_text.mu
parentd63cddeac0f5fb7eeaeacf828765965e9b61b6ca (diff)
downloadmu-b75d9d456cb36ad41ab735586473adbbf3444643.tar.gz
3365 - create strings out of arbitrary types
The implementation is quite hacky. Let's see how future needs develop
before we try to clean it up.
Diffstat (limited to '059to_text.mu')
-rw-r--r--059to_text.mu17
1 files changed, 17 insertions, 0 deletions
diff --git a/059to_text.mu b/059to_text.mu
index 207ade78..30761eb9 100644
--- a/059to_text.mu
+++ b/059to_text.mu
@@ -29,3 +29,20 @@ scenario array-to-text-line-early-warning-for-static-dispatch [
   x:text <- array-to-text-line n
   # just ensure there were no errors
 ]
+
+# finally, a specialization for single characters
+def to-text c:character -> y:text [
+  local-scope
+  load-ingredients
+  y <- new character:type, 1/capacity
+  *y <- put-index *y, 0, c
+]
+
+scenario character-to-text [
+  1:character <- copy 111/o
+  2:text <- to-text 1:character
+  3:array:character <- copy *2:text
+  memory-should-contain [
+    3:array:character <- [o]
+  ]
+]