Skip to content

Commit

Permalink
dict keys/values: sort for now [FIXME: insertion order?!]
Browse files Browse the repository at this point in the history
  • Loading branch information
obfusk committed Aug 29, 2024
1 parent fe249b5 commit 94ff630
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions js/koneko.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/Koneko/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94ff630

Please sign in to comment.