Sujet : Re: recursion
De : sjack (at) *nospam* dontemail.me (sjack)
Groupes : comp.lang.forthDate : 16. Jul 2024, 20:39:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v76i8v$1di81$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : tin/2.6.2-20220130 ("Convalmore") (Linux/6.5.0-41-generic (x86_64))
minforth <
minforth@gmx.net> wrote:
Pretzel coding. I wondered what that could be useful for.
Kind of wonder why myself; more focused on ways to do the given
example rather than why it's needed to be a forward case. By the
way, the macro example I gave wasn't right; see example 5 for
correct way. Example 4 seems to me the most proper way as it
uses all basic Forth elements. Example 3 seems the best but it's
not a forwarding case so it may not be applicable to what's
being sought.
Example 1
: bar dup . 1- [ here tmp! ] noop ;
: foo dup 0> if bar [ latest pfa cfa tmp@ ! ] else drop then ;
5 foo5 4 3 2 1
Example 2
: forward here tmp! 0 , ; immediate
: resolve latest pfa cfa tmp@ ! ; immediate
: bar dup . 1- forward ;
: foo dup 0> if bar resolve else drop then ;
5 foo5 4 3 2 1
Example 3
: bar dup . 1- ;
: foo dup 0> if bar myself else drop then ;
5 foo5 4 3 2 1
Example 4
defer foo
: bar dup . 1- foo ;
anon dup 0> if bar else drop then ; is foo
5 foo5 4 3 2 1
Example 5
"here tmp! 0 ," /mm: forward
"latest pfa cfa tmp@ !" /mm: resolve
: bar dup . 1- [ mm forward ] ;
: foo dup 0> if bar [ mm resolve ] else drop then ;
5 foo5 4 3 2 1
-- remove all macros
mm.clear
-- do again
5 foo5 4 3 2 1
-- me