From 94ff630c01f86492b7f8b2348d93b69d2e548038 Mon Sep 17 00:00:00 2001 From: "FC (Fay) Stegerman" Date: Thu, 29 Aug 2024 03:11:01 +0200 Subject: [PATCH] dict keys/values: sort for now [FIXME: insertion order?!] --- js/koneko.js | 5 +++-- src/Koneko/Eval.hs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/js/koneko.js b/js/koneko.js index 014355a..549249b 100644 --- a/js/koneko.js +++ b/js/koneko.js @@ -636,12 +636,13 @@ const call = (c0, s0, tailPos = false) => { // {{{1 } case "dict": { // TODO: inefficient implementation + // FIXME: insertion order?! const [opv, op, r] = popOp(), p = primPP(op, r) switch (opv) { case "keys": - return r(list([...xv.keys()].map(kwd))) + return r(list([...xv.entries()].sort().map(([k, v]) => kwd(k)))) case "values": - return r(list([...xv.values()])) + return r(list([...xv.entries()].sort().map(([k, v]) => v))) case "pairs": return r(list([...xv.entries()].sort().map( ([k, v]) => pair(kwd(k), v) diff --git a/src/Koneko/Eval.hs b/src/Koneko/Eval.hs index c7c8255..e0ae15b 100644 --- a/src/Koneko/Eval.hs +++ b/src/Koneko/Eval.hs @@ -239,13 +239,14 @@ callList (List l) _ s = do _ -> throwIO $ UnknownField (T.unpack op) "list" -- TODO +-- FIXME: insertion order?! callDict :: Dict -> Evaluator callDict (Dict h) _ s = do (Kwd op, s') <- pop' s let o = "dict." <> op; p = rpush1 s'; pr = p . mkOp o case op of - "keys" -> p $ map kwd $ H.keys h - "values" -> p $ H.elems h + "keys" -> p $ map (kwd . fst) $ sort $ H.toList h + "values" -> p $ map snd $ sort $ H.toList h "pairs" -> p [ pair (Kwd k) v | (k, v) <- sort $ H.toList h ] "merge" -> pr $ \_ s1 -> do (Dict h2, s2) <- pop' s1