I'm not sure what else is in your vector, but you could return -1 instead
of f, or some null object for which you define a comparison operator, or
just sift (it's probably fast enough even on large arrays).

sift is removing the first element here (vector looks like { f 1 2 3 4 5
... }

10,000,000 <iota> [ random ] map [ sift ] time
Running time: 0.251810384 seconds


On Wed, Jun 21, 2017 at 10:58 AM Alexander Ilin <ajs...@yandex.ru> wrote:

> In that case the behavior would be identical to the current one.
>
> 21.06.2017, 18:55, "Doug Coleman" <doug.cole...@gmail.com>:
>
> What should supremum do if you have no elements in the sequence?
>
> numpy throws an error too:
>
>
>
> In [1]: import numpy as np
>
> In [2]: np.max(np.array([]))
>
>
>
> ValueError: zero-size array to reduction operation maximum which has no
> identity
>
> On Wed, Jun 21, 2017 at 10:52 AM Alex Vondrak <ajvond...@gmail.com> wrote:
>
> Technically that case would be a matter of `supremum` handling empty
> arrays, not `f` elements per se.
>
>
> On Jun 21, 2017 8:48 AM, "Alexander Ilin" <ajs...@yandex.ru> wrote:
>
> ```
> { f f f f } sift supremum
> -> error is thrown
> ```
>
> 21.06.2017, 18:44, "Alex Vondrak" <ajvond...@gmail.com>:
>
> Or you could call `sift supremum`:
> http://docs.factorcode.org/content/word-sift,sequences.html
>
> Might be instructive to give the codebase a search, see how often that
> pattern is used. (Can't do it myself right now - on mobile.)
>
> On Jun 21, 2017 8:39 AM, "Alexander Ilin" <ajs...@yandex.ru> wrote:
>
> Hello!
>
>   How would you like if `supremum` tolerated the `f` elements?
>
>   Now:
> ```
>    { f 0 1 2 } supremum
>   -> error is thrown
>
>    { f f f f } supremum
>   -> error is thrown
> ```
>
>   Proposition:
> ```
>    { f 0 1 2 } supremum
>   -> 2
>
>    { f f f f } supremum
>   -> f
> ```
>
>   Current code:
> ```
> : supremum ( seq -- elt )
>     [ ] [ max ] map-reduce ;
> ```
>
>   Proposed code:
> ```
> : supremum ( seq -- elt )
>     [ ] [ 2dup and [ max ] [ dupd ? ] if ] map-reduce ;
> ```
>
>   If you like what you are seeing, I'll make a formal PRoposal.
>
> ---=====---
>  Александр
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
> ,
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ,
>
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
>
> ---=====---
> Александр
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
> ,
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ,
>
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
>
> ---=====---
> Александр
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to