diff --git a/shared/static/scripts/sx.js b/shared/static/scripts/sx.js index a94ff97..09a6310 100644 --- a/shared/static/scripts/sx.js +++ b/shared/static/scripts/sx.js @@ -313,7 +313,7 @@ PRIMITIVES["list?"] = function (x) { return Array.isArray(x); }; PRIMITIVES["dict?"] = function (x) { return x !== null && typeof x === "object" && !Array.isArray(x) && !x._sym && !x._kw; }; PRIMITIVES["empty?"] = function (c) { return !c || (Array.isArray(c) ? c.length === 0 : Object.keys(c).length === 0); }; - PRIMITIVES["contains?"] = function (c, k) { return Array.isArray(c) ? c.indexOf(k) !== -1 : k in c; }; + PRIMITIVES["contains?"] = function (c, k) { return typeof c === "string" ? c.indexOf(k) !== -1 : Array.isArray(c) ? c.indexOf(k) !== -1 : k in c; }; PRIMITIVES["odd?"] = function (n) { return n % 2 !== 0; }; PRIMITIVES["even?"] = function (n) { return n % 2 === 0; }; PRIMITIVES["zero?"] = function (n) { return n === 0; }; diff --git a/shared/sx/primitives.py b/shared/sx/primitives.py index 9dd202b..ad74440 100644 --- a/shared/sx/primitives.py +++ b/shared/sx/primitives.py @@ -196,6 +196,8 @@ def prim_is_empty(coll: Any) -> bool: @register_primitive("contains?") def prim_contains(coll: Any, key: Any) -> bool: + if isinstance(coll, str): + return str(key) in coll if isinstance(coll, dict): k = key.name if isinstance(key, Keyword) else key return k in coll