Hi --

On Thu, 8 Aug 2002, Tom Sawyer wrote:

> did a little wondering about the internet, found this quote:
>
> Viewing Hash and Array as instances of "Container" leads
> to easy implementation of "Sparse Array" and "Sorted Hash"
> and "Real Array"

That's from a Perl 6 RFC; the same document also says:

   Hash keys are string, and Array keys are Integer

:-)

I'm not saying there isn't anything of interest for Ruby programmers
in looking at hashes and arrays together (if you search for "to_h
dblack" on ruby-talk, you'll see the evidence) -- just that
applicability of a Perl discussion to Ruby hashes is not self-evident.

> of course, what i'm suggesting is perhaps a bit more radical: unifying
> array and hash --well, perhaps just making a new type of object which is
> this unification (but given this, i can't exactly see why you'd still
> need the other two, but no matter)

For speed, convenience, flexibility... :-)  Unless your new type did
*everything* that *both* arrays and hashes do (rather than just the
intersection), it would not serve to replace either.  You'd just end
up feeling the need for a hash/dictionary/associative array type of
type, and have to create it.

> this new "MixedContainer" class could have a literal representation
> denoted by parantheticals:
>
> 	( 'one', :opkey=>'two' )

I don't think you can use parentheses as a constructor for a
particular type of object -- they can go around almost anything.

In any case, the above looks to me like it could be handled easily by
an array:


  [ "one", { :opkey => "two" } ]


> then a subclass of Container could be made called Arguments, where
> Arguments has some added features that give it some of the reminaing
> applicaple characteristics of Ruby's current argument behavior, ie.
> *array, &block and the like.
>
> thus, calling any method simply boils down to passing a single Arguments
> object.
>
> 	f ('one', :opkey=>'two')
>
> which then could also be done like this:
>
> 	args = ('one', :opkey=>'two')
> 	f args
>
> the end result? we get a new powerful class and named parameters in one
> shot.
>
> neat/clean/interestig idea?

I have to admit that the hash/array merger/elimination concept, and
the Arguments class, strikes me as a solution in search of a problem.
I may be wrong about that, but I don't think named parameters (if
they're indeed a good and welcome idea) should hitch their wagon to
it.

I guess I tend to judge named parameter syntax examples by how much
punctuation they add to the landscape.  Yours comes in pretty high on
that scale :-)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav