Creating and using arrays - again
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.forth Profile…
 Up
Creating and using arrays - again         


Author: Duke Normandin
Date: Mar 21, 2008 08:54

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@tigger:~]$ 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_ .
Show full article (0.89Kb)
65 Comments
Re: Creating and using arrays - again         


Author: Elizabeth D Rather
Date: Mar 21, 2008 09:49

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@tigger:~]$ 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
> ...
Show full article (1.98Kb)
no comments
Re: Creating and using arrays - again         


Author: Jonah Thomas
Date: Mar 21, 2008 09:14

Duke Normandin ml1.net> wrote:
> I've come up with something that works for me. Would you folks
> critique it please, and let me know any potential pitfalls.
> : } 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?
Show full article (1.24Kb)
no comments
Re: Creating and using arrays - again         


Author: Bruce McFarling
Date: Mar 21, 2008 10:20

On Mar 21, 11:54 am, Duke Normandin ml1.net> 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@tigger:~]$ 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
Show full article (1.66Kb)
no comments
Re: Creating and using arrays - again         


Author: Duke Normandin
Date: Mar 21, 2008 11:36

On Fri, 21 Mar 2008, Bruce McFarling wrote:
>
>
> On Mar 21, 11:54 am, Duke Normandin ml1.net> wrote:
>> I've come up with something that works for me. Would you folks critique it
>> please, and let me know any potential pitfalls....
Show full article (2.07Kb)
no comments
Re: Creating and using arrays - again         


Author: Duke Normandin
Date: Mar 21, 2008 11:51

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@tigger:~]$ gforth...
Show full article (2.13Kb)
no comments
Re: Creating and using arrays - again         


Author: Duke Normandin
Date: Mar 21, 2008 11:57

On Fri, 21 Mar 2008, Jonah Thomas wrote:
>
>
> Duke Normandin ml1.net> wrote:
>
>> I've come up with something that works for me. Would you folks
>> critique it please, and let me know any potential pitfalls.
>
>> : } cells + ...
Show full article (1.74Kb)
no comments
Re: Creating and using arrays - again         


Author: Jonah Thomas
Date: Mar 21, 2008 12:28

ODuke Normandin ml1.net> wrote:
> 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?

On some systems there could be a speed advantage. Part of the DOES>
might be in optimised code that's a little faster than calling your own
word. It's possible.

Maybe more important, it gives you a way to make your own new data
structures that do whatever you want, and the syntax is simple and easy
once the CREATE DOES> is done. Once ARRAY does what you want it to, you
can make as many ARRAYs as you want. Maybe
Show full article (1.38Kb)
no comments
Re: Creating and using arrays - again         


Author: Elizabeth D Rather
Date: Mar 21, 2008 13:16

Duke Normandin wrote:
> On Fri, 21 Mar 2008, Elizabeth D Rather wrote:
...
>
>> A more Forthish approach would be:
>>
>> : ARRAY ( n -- ) CREATE CELLS ALLOT
>>> ( i -- i-addr ) CELLS + ;
>
> I'm just now clueing in on Forth's 'double-barrel' / 'delayed-duet'
> capability of CREATE / DOES>

The best way to think about it is that the part before the DOES>
specifies a class of words with a shared defining behavior. The part
after the DOES> defines the shared behavior of all instances of this
class of definitions.
Show full article (1.37Kb)
no comments
Re: Creating and using arrays - again         


Author: Duke Normandin
Date: Mar 21, 2008 13:37

On Fri, 21 Mar 2008, Elizabeth D Rather wrote:
>
>
> Duke Normandin wrote:
>> On Fri, 21 Mar 2008, Elizabeth D Rather wrote:
> ...
>>
>>> A more Forthish approach would be:
>>>
>>> : ARRAY ( n -- ) CREATE CELLS ALLOT
>>>> ( i -- i-addr ) CELLS + ;
>>
>> I'm just now clueing in on Forth's 'double-barrel' / 'delayed-duet'
>> capability of CREATE / DOES>
>
> The best way to think about it is that the part before the DOES> specifies a
> class of words with a shared defining behavior. The part after the DOES>
> defines the shared behavior of all instances of this class of definitions.
Show full article (1.49Kb)
no comments
1 2 3 4 5 6 7