On Sun, 5 Sep 2004, Hal Fulton wrote:

>> Or are you just wanting arrays that take arbitrary subscripts?
>>
>
> Probably so, yes. With the condition that a convenient syntax for
> literals should exist.


   jib:~ > cat a.rb
   require 'arrayfields'

   a = [0,1,2]
   a.fields = %w(zero one two)
   a['three'] = 3
   a.each_with_field{|k,v| puts "#{ k } -> #{ v }"}


   jib:~ > ruby a.rb
   0 -> zero
   1 -> one
   2 -> two
   3 -> three


arrayfields does a whole lot more that this


   jib:~ > cat b.rb
   require 'arrayfields'

   fa =
     FieldedArray[
       'zero', 0,
       'one', 1,
       'two', 2,
       'three', 3,
     ]

   fa.each_pair{|k,v| puts "#{ k } -> #{ v }"}

   a = [0,1,2,3]
   a.fields = fa.fields

   a.store 'three', 42
   p a['three']
   p a.keys
   p a.values

   jib:~ > ruby b.rb
   zero -> 0
   one -> 1
   two -> 2
   three -> 3
   42
   ["zero", "one", "two", "three"]
   [0, 1, 2, 42]

i think the literal syntax is pretty clear:

   jib:~ > cat c.rb
   require 'arrayfields'

   fa = FieldedArray[
     ['zero',  0],
     ['one',   1],
     ['two',   2],
     ['three', 3],
   ].each_pair{|k,v| puts "#{ k } -> #{ v }"}

   fa = FieldedArray[
     'zero',  0,
     'one',   1,
     'two',   2,
     'three', 3,
   ].each_pair{|k,v| puts "#{ k } -> #{ v }"}


   jib:~ > ruby c.rb
   zero -> 0
   one -> 1
   two -> 2
   three -> 3
   zero -> 0
   one -> 1
   two -> 2
   three -> 3


kind regards.

-a
--
===============================================================================
| EMAIL   :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE   :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it. 
|   --Dogen
===============================================================================