On Mar 24, 2007, at 2:58 PM, Dr Gerard Hammond wrote:

> I couldn't agree more John. The speed of dictionaries is great but
> the syntax is awfully confusing.
>
> I am forever going back to working version of dictionary code to copy
> and paste.
> For some reason, the current syntax just never makes sense to me.
>
> Maybe we should fix this ourselves, using the 'extends' keyword to
> modify the dictionary object syntax. (It might even show us why the
> syntax is the way it is?)

A simple wrapping of a dictionary into a "tuple" can be pretty quick  
and painless

1) create a new class called Tuple
2) add a private property as Dictionary (call it mProperties)
3) add a Constructor with this code

        mProperties = new Dictionary

4) define the operator_lookup method that takes a string parameter  
called name and returns a variant with this code

        operator_lookup(name as string) as variant

                if mProperties.hasKey(name) then
                        return mProperties.value(name)
                else
                        return "" // that return 0 as assignment to a string 
will give "0"
                end if

5) add a method for adding values. This is also an operator_lookup  
method but ASSIGNS a variant

        operator_lookup(name as string, assigns v as variant)

                mProperties.value(name) = v


At this point in your code you can do

   dim t as tuple

   t = new Tuple
   t.i = 123
   t.s = "456"

   dim i as integer
   dim s as string

   i = t.i
   s = t.s

Of course you could also do

   s = t.i
   i = t.s

And you would get whatever coercions from one type to another that  
variants already perform

IF there were some way to provide type safety that would be good :)
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to