brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 111 forks source link

List `filter` relies on JavaScript filter raw list filter, which is truthy/falsy #1624

Closed jchen closed 6 months ago

jchen commented 3 years ago

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

Source at line 390 in src/arr/trove/lists.arr.

jpolitz commented 3 years ago

Nice catch! Pushed a fix that will go out the next time we do an incremental deploy of important-but-not-showstopping stuff, this fall sometime.

blerner commented 6 months ago

Fixed by now.