Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Creating an...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 65 Topic 3945 of 4285
Post > Topic >>

Re: Creating and using arrays - again

by Duke Normandin <dukeofperl@[EMAIL PROTECTED] > Mar 21, 2008 at 06:51 PM

On Fri, 21 Mar 2008, Elizabeth D Rather wrote:

>
>
> Duke Normandin wrote:
> > I've come up with something that works for me. Would you folks
critique it
> > please, and let me know any potential pitfalls.
> >
> > [23:21:03][dnormandin@[EMAIL PROTECTED]
 gforth
> > Gforth 0.6.2, Copyright (C) 1995-2003 Free Software Foundation, Inc.
> > Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
> > Type `bye' to exit
> >
> > : } cells + ; ( addr n -- n-addr ) ok
> >   ok
> > create ages{ 10 cells allot  ok
> >   ok
> > 15 ages{ 0 } !  ok
> > 60 ages{ 1 } !  ok
> > 25 ages{ 2 } !  ok
> >   ok
> > ages{ 1 } ? 20  ok
> > cr ." I am " ages{ 1 } ? ." years old!" cr
> >
> > I'm going to make it a practice to name my arrays with a trailing { in
> > order to use the word } and have the whole thing look like something
I'm
> > used to and seems intuitive _to me_ .
> >
> > What do you think, folks?
>
> The acid test is what it looks like in a loop, since that's how most
arrays
> are used.  So, you might have:
>
> 10 CONSTANT SIZE
> CREATE DATA{  SIZE CELLS ALLOT
> : GET-DATA ( -- )   SIZE 0 DO
>    GETNUM  DATA{ I } !  LOOP ;
>
> Not bad.  Note that defining the size as a CONSTANT is useful because if
you
> reference it every time you do something with the array, you can change
the
> size just by changing this one place and recompiling.  Much better than
trying
> to find all the 10's and deciding whether this one needs changing or is
just
> 10-something-else.

Great suggestion!

> A more Forthish approach would be:
>
> : ARRAY ( n -- )   CREATE  CELLS ALLOT
>    DOES> ( i -- i-addr )   CELLS + ;

I'm just now clueing in on Forth's 'double-barrel' / 'delayed-duet'
capability of CREATE / DOES>

> 10 CONSTANT SIZE
> SIZE ARRAY MYDATA
> : GET-DATA ( -- )   SIZE 0 DO
>    GETNUM  I DATA !  LOOP ;

Is there a speed advantage in using CREATE / DOES> and burying part of the
code in the DOES> routine? Or is it simply a more "traditional" approach?
-- 
Duke Normandin
dukeofperl@[EMAIL PROTECTED]
 Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
 




 65 Posts in Topic:
Creating and using arrays - again
Duke Normandin <dukeof  2008-03-21 15:54:28 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-21 11:49:44 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-21 18:51:11 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-21 15:16:05 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-21 20:37:06 
Re: Creating and using arrays - again
JK <jk.usenet@[EMAIL P  2008-03-21 14:59:30 
Re: Creating and using arrays - again
Albert van der Horst <  2008-03-22 12:19:21 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-22 21:53:06 
Re: Creating and using arrays - again
Jonah Thomas <jethomas  2008-03-21 12:14:43 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-21 18:57:07 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-22 12:55:51 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-22 17:35:49 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-22 13:58:37 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-22 14:02:28 
Re: Creating and using arrays - again
kenney@[EMAIL PROTECTED]   2008-03-23 14:37:59 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-21 10:20:33 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-21 18:36:16 
Re: Creating and using arrays - again
Jonah Thomas <jethomas  2008-03-21 15:28:15 
Re: Creating and using arrays - again
Krishna Myneni <krishn  2008-03-21 20:20:55 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-22 03:06:35 
Re: Creating and using arrays - again
Duke Normandin <dukeof  2008-03-22 17:32:04 
Re: Creating and using arrays - again
"Mark W. Humphries&q  2008-03-21 21:05:28 
Re: Creating and using arrays - again
Andrew Haley <andrew29  2008-03-22 14:33:04 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-22 06:01:33 
Re: Creating and using arrays - again
Jonah Thomas <jethomas  2008-03-22 10:29:43 
Re: Creating and using arrays - again
Andrew Haley <andrew29  2008-03-22 14:36:34 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-22 12:48:49 
Re: Creating and using arrays - again
<Montesquiou>   2008-03-22 19:23:19 
Re: Creating and using arrays - again
Andrew Haley <andrew29  2008-03-22 22:19:36 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-22 22:45:21 
Re: Creating and using arrays - again
Andrew Haley <andrew29  2008-03-23 12:13:19 
Re: Creating and using arrays - again
Coos Haak <chforth@[EM  2008-03-23 13:37:55 
Re: Creating and using arrays - again
Andrew Haley <andrew29  2008-03-23 13:06:36 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-23 09:10:08 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-23 10:50:39 
Re: Creating and using arrays - again
Andrew Haley <andrew29  2008-03-23 15:50:35 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-23 10:49:26 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-23 10:47:31 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-23 11:33:59 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-25 17:39:47 
Re: Creating and using arrays - again
Dennis Ruffer <druffer  2008-03-26 00:57:35 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-25 20:43:54 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-26 11:00:22 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-22 08:44:53 
Re: Creating and using arrays - again
"Mark W. Humphries&q  2008-03-22 11:16:58 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-22 12:05:35 
Re: Creating and using arrays - again
Jonah Thomas <jethomas  2008-03-22 17:02:25 
Re: Creating and using arrays - again
Josh Grams <josh@[EMAI  2008-03-23 13:18:16 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-23 08:53:42 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-22 16:03:57 
Re: Creating and using arrays - again
Jerry Avins <jya@[EMAI  2008-03-22 22:46:54 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-23 06:23:42 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-23 06:46:58 
Re: Creating and using arrays - again
Albert van der Horst <  2008-03-24 02:48:31 
Re: Creating and using arrays - again
"Mark W. Humphries&q  2008-03-23 08:40:13 
Re: Creating and using arrays - again
Jonah Thomas <jethomas  2008-03-23 12:32:11 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-23 12:02:17 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-23 14:17:56 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-23 17:48:14 
Re: Creating and using arrays - again
Jonah Thomas <jethomas  2008-03-23 18:55:28 
Re: Creating and using arrays - again
Elizabeth D Rather <er  2008-03-23 19:02:53 
Re: Creating and using arrays - again
"Mark W. Humphries&q  2008-03-23 17:26:40 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-23 21:13:31 
Re: Creating and using arrays - again
Albert van der Horst <  2008-03-24 15:51:05 
Re: Creating and using arrays - again
Bruce McFarling <agila  2008-03-24 09:27:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 14:02:16 CDT 2008.