A stack effect of ( seq quot -- ) doesn't say what the quot is expected to
do...

You can play around with it and see how it works:

    IN: scratchpad "abc" [ "empty" ] when-empty .
    "abc"

    IN: scratchpad "" [ "empty" ] when-empty .
    "empty"

We should improve the docs here because they are a little hard to follow,
since it refers to ``when-empty`` taking the "first quot" of an
``if-empty``, with an empty second quot.




On Wed, Mar 1, 2017 at 8:18 AM, Alexander Ilin <ajs...@yandex.ru> wrote:

> Hello!
>
>   I'm struggling with some of the Factor's words. Mostly with
> `when-empty`, `if-zero` and similar. It's difficult for me to understand
> why they don't work sometimes, while their simpler counterparts (while, if)
> do work exactly as expected.
>
>   Here's the latest installment of my struggle:
>
> IN: scratchpad USE: crypto.xor [ [ empty-xor-key ] when-empty ]  infer.
> ( x -- x )
>
>   Why is the stack effect as shown here? The documentation for
> `when-empty` says it takes `( seq quot -- )`. Therefore, I expect `[ [
> empty-xor-key ] when-empty ]  infer.` to output `( x -- )`.
>
>   When I modify the quotation passed to `when-empty` to be a no-op, I get
> a compilation error:
> IN: scratchpad [ [ 1 drop ] when-empty ]  infer.
> Error
> The input quotations to “if-empty” don't match their expected effects
> Input      Expected           Got
> [ 1 drop ] ( ..a -- ..b )     ( -- )
> [ ]        ( ..a seq -- ..b ) ( -- )
>
>   That's completely weird to me. Is the stack effect in the documentation
> incorrect? Should it be `( seq quot -- seq )`?
>   And why does it refuse to compile the second example with `1 drop`?
>
> ---=====---
>  Александр
>
> ------------------------------------------------------------
> ------------------
> 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