List filter is not currently enforcing that function passed in is a predicate (that is, return a Boolean value). Instead, it seems to rely on JavaScript raw list filter which is determined using JavaScript truthy/falsy values. Functions can return non Boolean values and built-in filter will admit them (as JavaScript does). For example, Pyret accepts the following tests:
check:
[list: -1, 0, 1, 2].filter(lam(x): x end)
is [list: -1, 1, 2]
[list: "hello", "", "world", "a"].filter(lam(x): x end)
is [list: "hello", "world", "a"]
end
List
filter
is not currently enforcing that function passed in is a predicate (that is, return aBoolean
value). Instead, it seems to rely on JavaScript raw list filter which is determined using JavaScript truthy/falsy values. Functions can return nonBoolean
values and built-in filter will admit them (as JavaScript does). For example, Pyret accepts the following tests:Source at line 390 in
src/arr/trove/lists.arr
.