Both of those are macros (basically special words that produce a
quotation), so when "called" they are first macro-expanded into a quotation
and then that quotation is called, with whatever stack effect it has.

IN: scratchpad 1 2 3 "%s %s %s" printf
1 2 3

IN: scratchpad [ "%s %s %s" printf ] infer
( x x x -- )

IN: scratchpad [ "%s %s %s" printf ] expand-macros
[
    [ present ] 2 ndip [ " " ] 2 ndip [ present ] 1 ndip
    [ " " ] 1 ndip [ present ] 0 ndip output-stream get
    [ stream-write ] curry 5 napply
]

Maybe the article I wrote when developing it would help:

https://re-factor.blogspot.com/2011/08/printf.html


On Thu, Jan 18, 2018 at 4:32 AM, Alexander Ilin <ajs...@yandex.ru> wrote:

> Hello!
>
>   There are two similar words: printf and sprintf. They have similar stack
> effects, but different behavior.
>
> MACRO: sprintf ( format-string -- result )
> leaves a string on stack
>
> MACRO: printf ( format-string -- quot )
> leaves nothing on stack despite the stack effect specified
>
>   How come `printf` does'n obey its declared stack effect?
>
> ---=====---
>  Александр
>
>
> ------------------------------------------------------------
> ------------------
> 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