Google Groups Home
Help | Sign in
Message from discussion Shorter/better way to do this?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
jzakiya  
View profile
 More options 15 Oct 2008, 16:25
Newsgroups: comp.lang.forth
From: jzakiya <jzak...@mail.com>
Date: Wed, 15 Oct 2008 08:25:23 -0700 (PDT)
Local: Wed 15 Oct 2008 16:25
Subject: Re: Shorter/better way to do this?
On Oct 15, 1:28 am, "roger.l...@gmail.com" <roger.l...@gmail.com>
wrote:
> > Maybe you haven't noticed but this is a Forth group and NOT Ruby.

> > FYI I use Ruby, and the Ruby versions of this code does not use nor
> > need these constructs because Ruby has dynamics arrays, which I can
> > grow or shrink to my hearts content. ONLY because arrays in Forth are
> > static do I have to resort to the described mechanism to fit stuff
> > into the array size domain of the "sieve" array, otherwise I could let
> > the array grow (as I do in Ruby) and then shrink it back to the
> > desired length when it matters.

> > Also FYI, you are not making Ruby friends by being a PITA about
> > posting none germain Ruby code to a specific Forth coding request. I
> > was hoping maybe there is some nice CASE structure, et al, that can do
> > what I want, in a more elegant and/or faster way.

> > When in Forthland speak Forth, please.

> > Jabari

> whoa, i think someone needs a chill pill, stat.

> is something like this the same as what you want to do?

> : carray   create allot does> swap + ;

> 8 carray p

> : clearsome
>    lndx 0 do  0 i p c!  loop ;

> i would try to do the other part, the begin/while loop, but i don't
> understand what 'sieve' is supposed to do.  does it influence 'lndx'?

--------------------

> whoa, i think someone needs a chill pill, stat.

It was late (actually early morning), I was tired/irritated, and that
response just crossed my threshold for patronizing irrelevance to my
very specific request. Also contributing to my irritation was that in
my 29 Forth years I believe I've seen ways to do what I was asking
(Forth Dimensions?) and was really irked by such an out of leftfield
response. But I meant no "personal" harm.  :-)

OK, now the code.

"lndx" is the array length (last index +1) for byte array "sieve"
The pi are index values into the "sieve" array.

I can functionally perform the same code equivalently like this:

begin p8 lndx < while 0 p8 sieve c!  x1 p8 + to p8 repeat
begin p7 lndx < while 0 p7 sieve c!  x1 p7 + to p7 repeat
begin p6 lndx < while 0 p6 sieve c!  x1 p6 + to p6 repeat
begin p5 lndx < while 0 p5 sieve c!  x1 p5 + to p5 repeat
begin p4 lndx < while 0 p4 sieve c!  x1 p4 + to p4 repeat
begin p3 lndx < while 0 p3 sieve c!  x1 p3 + to p3 repeat
begin p2 lndx < while 0 p2 sieve c!  x1 p2 + to p2 repeat
begin p1 lndx < while 0 p1 sieve c!  x1 p1 + to p1 repeat

This is shorter but MUCH slower on a single core/single threaded cpu
system. HOWEVER, this code represent CONCEPTUALLY exactly what I would
want to do if I had a system which could perform each line as a
separate independent simultaneous thread, ala a parallel processor/
threaded system. (For my Ruby friend, I performed a Ruby threaded
version using this approach which, because Ruby threads ARE NOT really
simultaneous parallel processes, is slower.)

So, when p8 < lndx is true, then all the other pi are < lndx too.
But when p8 >= lndx then pi < lndx will still be true for some pi and
what I want to do is find the pi for which pi < lndx is true and then
use all those pi to do   0 pi sieve c!   one last time.
So a "jump to/goto" structure would be ideal, to enable me to not have
to check for each  pi < lndx.  Comprendes toto?

And for my Ruby friend again, in the Ruby version all I have to do
is:  while  p1 < lndx ....end  and let the array grow past the real
size I need, and then I "squeeze" it to eliminate "nils" when its time
to do final processing of the "sieve" array.

: clearsome  lndx 0 do  0 i p c!  loop ;
sets all the array elements of "0" which is not want I want.

I hope this now provides sufficient understanding of my code,

Jabari


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google