Commit38f91d4bRecorded16 Mar 2026Repositorysigil-yaml
Fix YAML encoder to handle Sigil arrays
Message
yaml-encode now converts arrays to lists before serializing, so JSON-decoded arrays (which become Sigil arrays, not lists) are written as proper YAML sequences instead of #<object>.
Changed
src/sigil/yaml.sgl | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)Diff
src/sigil/yaml.sglmodified
@@ -57,7 +57,8 @@
57
(define-library (sigil yaml) 58
(import (sigil string) 59
(sigil io)−60
(sigil math))+60
(sigil math)+61
(sigil array)) 62
(export 63
;; Port-based I/O 64
yaml-read@@ -1067,6 +1068,9 @@
1068
;; Dict as mapping 1069
((dict? value) 1070
(yaml-write-block-mapping value port indent-size depth top-level?))+1071
;; Array as sequence (convert to list)+1072
((array? value)+1073
(yaml-write-block-value (array->list value) port indent-size depth top-level?)) 1074
;; List as sequence 1075
((pair? value) 1076
(yaml-write-block-sequence value port indent-size depth top-level?))@@ -1091,7 +1095,7 @@
1095
(let ((pair (car pairs))) 1096
(yaml-write-key (car pair) port) 1097
(let ((val (cdr pair)))−1094
(if (or (dict? val) (and (pair? val) (not (null? val))))+1098
(if (or (dict? val) (array? val) (and (pair? val) (not (null? val)))) 1099
(begin 1100
(display ":" port) 1101
(newline port)@@ -1110,7 +1114,7 @@
1114
(display prefix port)) 1115
(display "- " port) 1116
(let ((val (car items)))−1113
(if (or (dict? val) (and (pair? val) (not (null? val))))+1117
(if (or (dict? val) (array? val) (and (pair? val) (not (null? val)))) 1118
(begin 1119
;; For collections, write inline start 1120
(yaml-write-block-value val port indent-size (+ depth 1) #f))@@ -1200,6 +1204,7 @@
1204
(define (yaml-write-flow-value value port) 1205
(cond 1206
((dict? value) (yaml-write-flow-mapping value port))+1207
((array? value) (yaml-write-flow-value (array->list value) port)) 1208
((pair? value) (yaml-write-flow-sequence value port)) 1209
((null? value) (display "[]" port)) 1210
(else (yaml-write-scalar value port))))