You can get similar behavior if you want a less general approach by doing
something like this, using the word symbol as a variable:

: foo ( x -- y )
    \ foo [
        [ 1 + ] unless t
    ] change-global ;

IN: scratchpad 1 foo .
2

IN: scratchpad 1 foo .
1





On Wed, Aug 23, 2017 at 3:33 AM, Alexander Ilin <ajs...@yandex.ru> wrote:

> Actually, a better name might be `do-once`, or `with-guard-var`, or
> similar.
>
> 23.08.2017, 13:30, "Alexander Ilin" <ajs...@yandex.ru>:
> > Hello!
> >
> >   I think I came up with a useful word. Don't we already have something
> of this nature?
> >
> > : unless-global-var ( guard-variable quot -- )
> >     dupd '[ t _ set-global @ ] [ get-global ] dip unless ; inline
> >
> > ---=====---
> >  Александр
> >
> > ------------------------------------------------------------
> ------------------
> > 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