Arrays: new and old keys, i
Trevor DeVore
lists at mangomultimedia.com
Thu Sep 11 16:49:04 EDT 2008
On Sep 11, 2008, at 4:27 PM, David Bovill wrote:
>> I have another scenario where I had to resort to 'do' though. I'm
>> converting
>> SQL queries to a hierarchal array but unlike XML SQL results have
>> no sense
>> of hierarchy. So I have a couple of 'do' statements in the code
>> which I will
>> promptly replace when/if the engine is updated to support dynamic
>> keys.
>
> I can't quite follow the details of this but I am sure it is a very
> powerful
> and important feature to add. I love the ability to have variable
> properties
> for instance. It is so powerful to be able to do this without speed
> penalties:
>
> put "name" into someProperty
> put the someProperty of btn 1
Same basic idea. You just want to be able to do something like:
put "[people][1][name]" into theKey
and then use theKey to target a specific key in the array somehow.
Some pseudo code:
put key theKey of theArrayA into theValue
Right now we have to do something like this:
put "some string" into theValue
put "[people][1][name]" into theKey ## assume you didn't know the full
path to the key in advance.
put "put theValue into theArrayA" & theKey into theDo
do theDo
> I really like the way lua does this - in particular their concept of
> meta(data)tables. You can define a default array in this metatable,
> and then
> if a vlaue in your array is not set it returns the default value.
> This is
> great for things like translations - and I've often use this data
> structure
> going back to Hypercard days. Maybe its not core - but I ffigure if
> you are
> going to implement a new datastructure why not learn from the best.
> Adding
> things like sorted indexes could be done to the metatable without
> affecting
> any backward compatability issues. Really no more than a suggestion /
> thought :)
Now that we have a new data structure it definitely makes you hungry
for more. The easier it is to represent the data you are working with
using built-in data structures the easier it is to code in that
environment. Multi-dimensional arrays are a great addition and
hopefully it is a sign of more things to come.
> Great functions though Trevor - thanks. Looks like it will be worth
> using
> arrays for tree structures. Do you know by the way what the limits
> on keys
> are, and can we now pass arrays to seprop handlers? That would be very
> usefull for me as I often define getprop handlers that return arrays
> - but
> have to limit this as there is no way to implement a corresponding
> setprop.
I do not know what the limits are. I was unsuccessful in my attempt to
pass multi-dimensional arrays in setProp handlers. But since you can
'send' arrays now you can define your setProp handlers using command
and use 'send' instead.
Regards,
--
Trevor DeVore
Blue Mango Learning Systems
www.bluemangolearning.com - www.screensteps.com
More information about the use-livecode
mailing list