Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: Strings and numbers Date: Sun, 13 Sep 2015 00:12:14 -0700 Organization: A noiseless patient Spider Lines: 34 Message-ID: <87bnd6sshd.fsf@jester.gateway.pace.com> References: <87egjjk8kn.fsf@jester.gateway.sonic.net> <877fo0t4y0.fsf@jester.gateway.pace.com> <99b72d58-0b1a-4e09-9c34-42ebb844fff8@googlegroups.com> <87oah9st2o.fsf@jester.gateway.pace.com> <7344e907-150a-4908-8fb3-7e5721796600@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="3a9ed331cf606b0b072b7def4034f06f"; logging-data="25985"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kCXRZu5KK7lnLo/wQF+0c" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:aMC4xF2UaXF+0gy7dLDJ+6NksnA= sha1:ogxHSruDkTDSJwZdo7kEYdsD7gs= Xref: csiph.com comp.lang.forth:41981 humptydumpty writes: > Is noteworthy that dynamically using variables, unlike using locals, > permits factoring. Yeah, I think the code I posted with the locals could have been arranged to use the stack (maybe easier with 2 args instead of 3) but I didn't feel up to the effort. Static variables of course don't work with recursive functions where the locals need different values at different call levels. I wrote some other recursive code a while back where I didn't want to even think about how to get rid of the locals. Here you do it by carefully modifying the global, using it, then unmodifying it in order to backtrack. I think for the most part, the no-locals style is harder for this sort of thing. But it's nice to see you and Richard posting code without them. > Just for factoring sake, under dynamically use of variable 'Bmp': > : >{ ]] dup @ 2>R [[ ; IMMEDIATE > : } ]] R> R> ! [[ ; IMMEDIATE What are ]] and [[ ? They're not in the gforth manual word index. > VARIABLE Bmp VARIABLE N > DEFER run ( u -- ) What's the purpose of deferring run? I thought maybe it was for mutually recursive functions but I didn't see anything that needed it. > prologue > 2dup N @ swap - mod 0= > IF RECURSE THEN > epilogue I guess this uses less memory than leaving all that stuff on the stack in the locals version.