changeset 536:b946346870ae

Add json function
author Chris Cannam
date Mon, 17 Mar 2014 15:21:48 +0000
parents d8a967b0f909
children 8c26ccf36416
files src/may/matrix.yeti
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/may/matrix.yeti	Mon Mar 17 11:09:53 2014 +0000
+++ b/src/may/matrix.yeti	Mon Mar 17 15:21:48 2014 +0000
@@ -42,6 +42,8 @@
 
 vec = load may.vector;
 
+load yeti.experimental.json;
+
 typedef opaque matrix_t = {
     size is { rows is number, columns is number },
     data is
@@ -894,6 +896,9 @@
 print' = println . format;
 eprint' = eprintln . format;
 
+json m =
+    jsonList (map do r: jsonList (map jsonNum (vec.list r)) done (asRows m));
+
 {
     size,
     width,
@@ -951,6 +956,7 @@
     format,
     print = print',
     eprint = eprint',
+    json,
 }
 as
 {
@@ -1010,5 +1016,6 @@
     format is matrix_t -> string,
     print is matrix_t -> (),
     eprint is matrix_t -> (),
+    json is matrix_t -> json,
 }