From 33af6b926680987f80a3da03e64a1ef6a5418f93 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Mar 2026 18:16:33 +0000 Subject: [PATCH] Fix serialize_value for SxExpr/Spread; handle List-of-SxExpr in aser output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit serialize_value was falling through to "nil" for SxExpr and Spread values. Now SxExpr passes through as raw SX text, Spread serializes as make-spread. The aser command's result handler now joins a List of SxExprs as a space-separated fragment (from map/filter producing multiple SxExprs). Investigation ongoing: handler aser responses still have "class" strings where :class keywords should be — the component expansion path in aser loses keyword types during CEK evaluation of component bodies. Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/bin/sx_server.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hosts/ocaml/bin/sx_server.ml b/hosts/ocaml/bin/sx_server.ml index 8402fe5..ff90249 100644 --- a/hosts/ocaml/bin/sx_server.ml +++ b/hosts/ocaml/bin/sx_server.ml @@ -59,6 +59,11 @@ let rec serialize_value = function (Printf.sprintf ":%s %s" k (serialize_value v)) :: acc) d [] in "{" ^ String.concat " " pairs ^ "}" | RawHTML s -> "\"" ^ escape_sx_string s ^ "\"" + | SxExpr s -> s + | Spread pairs -> + let items = List.map (fun (k, v) -> + Printf.sprintf ":%s %s" k (serialize_value v)) pairs in + "(make-spread {" ^ String.concat " " items ^ "})" | _ -> "nil" (** Request epoch — monotonically increasing, set by (epoch N) from Python. @@ -822,6 +827,15 @@ let rec dispatch env cmd = Use (ok-raw ...) so Python knows not to unescape. *) (match result with | String s | SxExpr s -> send_ok_raw s + | List items | ListRef { contents = items } -> + (* List of SxExprs from map/filter — join them as a fragment *) + let parts = List.filter_map (fun v -> match v with + | SxExpr s -> Some s + | String s -> Some ("\"" ^ escape_sx_string s ^ "\"") + | Nil -> None + | v -> Some (serialize_value v)) items in + if parts = [] then send_ok_raw "" + else send_ok_raw (String.concat " " parts) | _ -> send_ok_value result) with | Eval_error msg -> send_error msg