dec decrements a dynamically scoped variable. You're trying to use it for locals, which use a totally different mechanism for everything. For locals, there's no way right now to factor out a decrement function; you just have to read the local, subtract one and write the local. With this technique, your code could look like this:
: test ( -- ) [let | n! [ 10 ] | [ n zero? not ] [ n 1- n! n "%d\n" printf ] while ] ; In creating a local, if you use a name ending in ! then it will be a mutable local. The setter is called n! and the getter is called n Dan On Mon, Apr 6, 2009 at 1:05 PM, Ludovic Kuty <[email protected]> wrote: > Hi, > > I am trying to make a little example with a while loop. I plan to use > it in another context so I'd like to avoid using ranges (unless you > show me how to represent infinite sequences like all integers). The > code doesn't work because the n in "n dec" is not a symbol ? Nor a > variable ? I still don't understand how to use symbols because I > thought that I could avoid using SYMBOL: and still get the benefit of > variables. > I could do it with recursion (as with the test2 word) but instead I > try to use the while word specifically. > > Could you please show me how to rewrite my example ? Or maybe I cannot > alter the value of n inside [let. > > TIA > > Ludovic Kuty > > ! INFINITE LOOP !!!!! BUG > : test ( -- ) > [let | n [ 10 ] | [ n zero? not ] [ n dec n "%d\n" printf ] while ] > ; > > ! OK but I do not want this > :: test2 ( n -- ) > n zero? [ ] [ n "%d\n" printf n 1 - test2 ] if > ; > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > High Quality Requirements in a Collaborative Environment. > Download a free trial of Rational Requirements Composer Now! > http://p.sf.net/sfu/www-ibm-com > _______________________________________________ > Factor-talk mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/factor-talk > ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Factor-talk mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/factor-talk
