Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #28440

Re: suggestions for word names?

From Marcos Cruz <null_email_so_use_my_contact_page@programandala.net>
Newsgroups comp.lang.forth
Subject Re: suggestions for word names?
Date 2014-02-14 22:07 +0000
Organization Aioe.org NNTP Server
Message-ID <ldm427$sqr$1@speranza.aioe.org> (permalink)
References <ldlthk$bga$1@speranza.aioe.org> <odOdnZxtWrB34WPPnZ2dnUVZ_vWdnZ2d@supernews.com>

Show all headers | View raw


En/Je/On 2014-02-14, Elizabeth D. Rather escribió/skribis/wrote:
> On 2/14/14 10:15 AM, Marcos Cruz wrote:
>>    2>r dup dup 2r>  ( x1 x2 x3 -- x1 x1 x1 x2 x3 )
>>
>>    >r dup dup r>  ( x1 x2 -- x1 x1 x1 x2 )

> My recommendation is to re-think your stack usage and get rid of these 
> words altogether. Needing multiple copies of a single item is usually a 
> hint that your stack management could be better. For example, if you 
> start with ROT >R you get that x1 on the Return Stack where you can get 
> a copy of it whenever you need it by just saying R@ (and R> the last time).

You are right, Elizabeth. I often use 'r@' that way, but this time I
think it would make the code less simple.  This is an example of both
cases:

\ --------------------------------------------------------------
: (within-of)  ( x1 x2 x3 -- x1 x1 | x1 x1' )
  2>r dup dup 2r> within 0= if  invert  then
  ;
: within-of  ( compilation: -- of-sys ) ( run-time: x1 x2 x3 -- | x1 )
  postpone (within-of) postpone of
  ;  immediate compile-only

: (less-of)  ( x1 x2 -- x1 x1 | x1 x1' )
  >r dup dup r> >= if  invert  then
  ;
: less-of  ( compilation: -- of-sys ) ( run-time: x1 x2 -- | x1 )
  postpone (less-of) postpone of
  ;  immediate compile-only
\ --------------------------------------------------------------

The rest of the words are similar, only the inner condition changes.

So far that's the simplest code I've written for the task: to convert
the parameters of my customized of-variants to the pair of numbers
required by 'of'.

I could save the parameter into the return stack and manage it at the
end, but as said it looks less clear to me, because anyway two copies
are needed at the end:

  over >r >= if  r> dup invert  else  r> dup  then

That's why I find it easier to create the copies first:

  >r dup dup r> >= if  invert  then

Of course sure there are other alternatives I didn't think of.

Anyway, I simply wondered what other people do when a very specific
piece of code appears several times, but it's hard to name it apart in
order to factor it out.  In my case, it seems those two pieces of code
are not useful enough for other words, so a specific name, related to
this group of of-variants, will be the solution. 

Thank you.

-- 
Marcos Cruz
http://programandala.net

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

suggestions for word names? Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2014-02-14 20:15 +0000
  Re: suggestions for word names? "Elizabeth D. Rather" <erather@forth.com> - 2014-02-14 10:30 -1000
    Re: suggestions for word names? Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2014-02-14 22:07 +0000
      Re: suggestions for word names? humptydumpty <ouatubi@gmail.com> - 2014-02-15 10:00 -0800
        Re: suggestions for word names? Stefan Mauerhofer <smauerhofer@androsoft.ch> - 2014-02-18 05:04 -0800
          Re: suggestions for word names? m.a.m.hendrix@tue.nl - 2014-02-18 05:45 -0800
          Re: suggestions for word names? "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2014-02-18 18:17 -0500
            Re: suggestions for word names? Stefan Mauerhofer <smauerhofer@androsoft.ch> - 2014-02-18 21:38 -0800
            Re: suggestions for word names? Mark Wills <markrobertwills@yahoo.co.uk> - 2014-02-19 02:00 -0800
              Re: suggestions for word names? Paul Rubin <no.email@nospam.invalid> - 2014-02-19 02:44 -0800
              Re: suggestions for word names? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-02-19 20:13 +0000
          Re: suggestions for word names? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-02-19 03:49 -0600
    Re: suggestions for word names? Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-15 14:55 +0100
  Re: suggestions for word names? "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2014-02-14 20:44 -0500
    Re: suggestions for word names? Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-15 14:52 +0100
      Re: suggestions for word names? Coos Haak <chforth@hccnet.nl> - 2014-02-15 15:43 +0100
      Re: suggestions for word names? "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2014-02-15 12:06 -0500
        Re: suggestions for word names? Coos Haak <chforth@hccnet.nl> - 2014-02-15 18:30 +0100
        Re: suggestions for word names? Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-18 16:45 +0100
          Re: suggestions for word names? "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2014-02-18 18:17 -0500
            Re: suggestions for word names? Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-19 09:44 +0100
            Re: suggestions for word names? Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-19 09:47 +0100
              Re: suggestions for word names? Paul Rubin <no.email@nospam.invalid> - 2014-02-19 01:38 -0800
                Re: suggestions for word names? Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-19 16:59 +0100
            Re: suggestions for word names? Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-19 10:11 +0100
              Re: suggestions for word names? "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2014-02-19 05:39 -0500
                Re: suggestions for word names? Stefan Mauerhofer <smauerhofer@androsoft.ch> - 2014-02-19 03:31 -0800
    Re: suggestions for word names? Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2014-02-15 15:41 +0000

csiph-web