On Mon, Jun 29, 2009 at 3:11 PM, Harold Hausman<[email protected]> wrote:
> Thanks for this explanation, I think it makes sense. Is it then true
> to say that these two stack effects are equivalent:
> ( -- ? )
> ( x -- x ? )
>
> Or does the stack effect checker care? e.g., does it confirm that (at
> least?) the correct number of arguments are available?

It is important not to confuse formal stack effects in source, with
what is found in documentation.

The following is valid:

: my-word ( x -- x ? ) dup not ;

But the following is not; it will raise a compiler error and the word
will not run:

: my-word ( -- ? ) dup not ;

Stack comments in documentation are more informal. It is understood
that combinators, by convention, allow the quotation to 'see' the
underlying stack. This can be used to maintain state between
iterations in a looping combinator, for example by having the second
quotation to 'produce' perform some operation on the top of the stack.
Another example is the implementation of 'reduce' in terms of 'each':

: reduce ( seq elt quot -- ) swapd each ; inline

Indeed,

{ 1 2 3 } 0 [ + ] reduce

and

0 { 1 2 3 } [ + ] each

are equivalent, because the quotation [ + ] given to each will be
called with the sequence element at the top of the stack, and the
accumulator, initially 0, directly underneath.

So the answer is 'it depends'.

Slava

------------------------------------------------------------------------------
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to