
sorawee
2021-8-5 21:19:49
Using readtable for parsing works pretty well:
#lang racket
(define readtable/comma
(make-readtable
#f
#\,
#\space
#f))
(define read-table/brace
(make-readtable
readtable/comma
#\{
'terminating-macro
(λ (ch port src line col pos)
(~a "{"
(string-join (sort (map ~a (read/recursive port ch readtable/comma)) string<?) ",")
"}"))))
(define s "{{1,2}, {2,3}, {3,(4)}, {1,0}, {5,def}, {5,abc}}")
(parameterize ([current-readtable read-table/brace])
(read (open-input-string s)))
; "{{(4),3},{0,1},{1,2},{2,3},{5,abc},{5,def}}"