We don't really have a solution for this right now.

Your stack effects wouldn't match with the convention we have right now of
just saying it outputs a ``quot``. I think we need to fix the stack checker
to be more exact before we change the code here.

This looks more correct but goes against convention:

MACRO: printf ( ..a string -- ..b )
MACRO: sprintf ( ..a string -- ..b string )

On Thu, Jan 18, 2018 at 2:50 PM Alexander Ilin <ajs...@yandex.ru> wrote:

> Can I simply change the stack effects for the purposes of documenting them
> like this?
> ```
> MACRO: printf ( ... string -- )
> MACRO: sprintf ( ... string -- result )
> ```
>
>
> 18.01.2018, 23:44, "Doug Coleman" <doug.cole...@gmail.com>:
>
> Stack effects on macros are not checked. We have the convention of lying
> that the stack effect is ( input -- quot ) but even that is wrong, as the
> macro is called immediately so you don't get a quot on the stack. The quot
> could have a stack effect of its own but it's variable arity, as you are
> seeing with printf. If you have a way to resolve this, lemme know!
>
> (One idea is "input-only stack effects" which don't have an output, so you
> could do ``MACRO: printf ( string ) ... ;``)
>
> On Thu, Jan 18, 2018 at 2:36 PM Alexander Ilin <ajs...@yandex.ru> wrote:
>
> O-kay... Let me try to ask my question again...
>
> I've read the blog post that you linked to. In there I found the following
> declaration:
> `*MACRO:* printf ( format-string -- )`
>
> This means that the macro takes one argument and removes it from the
> stack, doesn't put anything back.
>
> But in the actual source code of the `formatting` vocab the declaration
> is: `MACRO: printf ( format-string -- quot )`, which looks as if the
> `printf` word takes one parameter off the stack and puts one item back on
> the stack.
>
> ... which is not true: it doesn't put a quotation on the stack, because it
> calls the quotation.
>
> So, I have two questions, basically:
>
> 1) why not change the declaration in `formatting` to ``MACRO: printf (
> format-string -- )` - with no output onto the stack?
> 2) are `MACRO:`s allowed to have invalid stack effect declaration? Are
> they somehow exempted from the compiler checks?
>
> I'm asking this because the declared stack effect shows up in the
> documentation, and is confusing. Reading it gives the expression that it
> should be used with an extra `call` to the produced quotation:
> `11 "he%do, world" printf call`
>
> 18.01.2018, 19:00, "John Benediktsson" <mrj...@gmail.com>:
>
> 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
>
>
>
> ---=====---
> Александр
>
>
> ------------------------------------------------------------------------------
> 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