Passing parameters by reference

Pete pete at mollysrevenge.com
Mon Mar 12 13:19:14 EDT 2012


Hi Dick,
Thanks again for this tip.  I ended up using it to solve my problem by
passing the whole array variable along with an optional second parameter
which is a list of comma-separated key values.  The function turns the key
values list into an array then uses it to access the data array.  If the
first parameter is a simple variable, then the second parameter isn't
present and the function can access it directly..

I'm wondering how you found about about this key values array feature?  I
can't find any mention of it in the dictionary or the reference manual and
it sure seems like something that should be known!

Thanks,
Pete

On Sat, Mar 10, 2012 at 12:06 AM, Dick Kriesel <dick.kriesel at mail.com>wrote:

> LC has a way to get and set a node at any level of an array, without code
> that concatenates [ ] to specify the node.  In an array reference a single
> [ ] can enclose an array of keys,
> -- Dick
>
>
> <script>
> on mouseUp
>   local tArray, tString
>   put 4 into tArray[ 1 ][ 2 ][ 3 ]
>   put getNodeViaListOfKeys( tArray, ( 1, 2, 3 )) after tString -- that is,
> get tArray[ 1 ][ 2 ][ 3 ]
>   setNodeViaListOfKeys tArray, ( 5, 6, 7, 8 ), 9 -- that is, put 9 into
> tArray[ 5 ][ 6 ][ 7 ][ 8 ]
>   put comma & getNodeViaListOfKeys( tArray, ( 5, 6, 7, 8 )) after tString
> -- 4,9
>   breakpoint
> end mouseUp
>
> function getNodeViaListOfKeys @pArray, pList
>   local tKeys
>   put pList into tKeys
>   split tKeys by comma and null
>   return getNodeViaArrayOfKeys( pArray, tKeys )
> end getNodeViaListOfKeys
>
> function getNodeViaArrayOfKeys @pArray, @pKeysArray
>   return pArray[ pKeysArray ]
> end getNodeViaArrayOfKeys
>
> command setNodeViaListOfKeys @rArray, pList, pValue
>   local tKeys
>   put pList into tKeys
>   split tKeys by comma and null
>   setNodeViaArrayOfKeys rArray, tKeys, pValue
> end setNodeViaListOfKeys
>
> command setNodeViaArrayOfKeys @rArray, @pKeysArray, @pValue
>   put pValue into rArray[ pKeysArray ]
> end setNodeViaArrayOfKeys
> </script>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>


-- 
Pete
Molly's Revenge <http://www.mollysrevenge.com>



More information about the use-livecode mailing list