From 64365b5c4f489f3b2f75bd9b5ade96d7dae62a05 Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Sat, 30 Aug 2025 01:13:24 +0200 Subject: [PATCH] c --- sexpr.ml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sexpr.ml b/sexpr.ml index d8eaf21..f3bb65a 100644 --- a/sexpr.ml +++ b/sexpr.ml @@ -500,7 +500,11 @@ module SExpr = struct append vv x, acc | _ -> raise Not_Sexpr_List - (* TODO: test aggr_flat_map *) + let () = test "SExpr.aggr_flat_map.0" @@ begin fun () -> + let a = Cons(Int 1, Cons(Int 2, Nil)) + and p = Cons(Int 1, Cons(Int 2, Cons(Int 2, Cons(Int 4, Nil)))) in + assert (fst (aggr_flat_map (fun aggr x -> Cons(x, Cons((match x with Int(n) -> Int(n + aggr) | x -> x) , Nil)) , aggr + 1) 1 a) = p) + end (* a "list" here is: * ( e1 . ( e2 . ( e3 . NIL ) ) ) @@ -682,6 +686,11 @@ module SExprMacroExp = struct let rec eval (ctx: (string * (SExpr.t * SExpr.t)) list) s = let open SExpr in + Format.printf "ctx:\n%!"; + List.iter begin fun vv -> + let k,v = vv in + Format.printf "- %s = %a%a\n%!" k pp_t (fst v) pp_t (snd v) + end ctx; let s, ctx = if is_list s then aggr_flat_map eval ctx s else @@ -721,11 +730,11 @@ module SExprMacroExp = struct end | s -> li1 s, false, ctx and check_expands_while ctx s = - let v, c, ctx = check_expands ctx s in + let s', c, ctx' = check_expands ctx s in if c then - check_expands_while ctx v + check_expands_while ctx' s' else - v, ctx + s', ctx' and match_macro_arg args margs = let open SExpr in match args, margs with