janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.48k stars 225 forks source link

(some) returns first truthy predicate result, not first truthy item #1350

Open iacore opened 9 months ago

iacore commented 9 months ago
repl:40:> (doc some)

    function
    boot.janet on line 2160, column 1

    (some pred ind & inds)

    Returns nil if (pred item) is false or nil for every item in ind. 
    Otherwise, returns the first truthy result encountered.

Is this intended? The return value isn't very useful this way.

iacore commented 9 months ago

I found find to do what I wanted. No idea if there is a function that maps to (all).

sogaiu commented 9 months ago

I agree that the docstring doesn't seem to match the actual behavior depending on specific arguments.

But I don't know what you mean by "return value isn't very useful":

$ janet
Janet 1.32.1-9142f38c linux/x64/gcc - '(doc)' for help
repl:1:> (some neg? [1 2 3 8])
nil
repl:2:> (some neg? [1 2 3 8 -1])
true

Doesn't this tell you something that was not necessarily known before the call?

iacore commented 9 months ago

But I don't know what you mean by "return value isn't very useful":

I mean (some ...) can easily just return true or false.

sogaiu commented 9 months ago

If the language was starting from scratch, may be a different choice might have been nicer.

Not so clear what the implications of changing behavior are at this point. But who knows...

iacore commented 9 months ago

how do i move this to /discussions/

sogaiu commented 9 months ago

I don't know -- I don't see an option in my view of this issue.

Perhaps it's reserved for some folks (like members of the janet-lang org)?