Array assignment / initialization [was Re: synonyms]

Alex Tweedly alex at tweedly.org
Thu Jun 29 09:21:44 EDT 2017


On 28/06/2017 23:32, Alex Tweedly via use-livecode wrote:
> Yes, it would be nice if we had an easier (terser) way to assign to an 
> array. Maybe something like Python / Perl use to assign to a dictionary.
>
>    put { "name": "my chart", "width": 100, "label": "This is a chart", 
> "anarray": sAMine } into tA
>    DoSomething tA
OK, here I go answering my own post (again).

function _
   local tA
   repeat with i = 1 to paramcount()
      put param(i+1) into tA[param(i)]
   end repeat
   return tA
end _

and then I can do

put _("name","my chart",   "width",100,   "label","This is a chart",   
"anarray",sAMine) into tA
DoSomething tA

or, indeed, even

DoSomething  _("name","my chart",   "width",100,   "label","This is a 
chart",   "anarray",sAMine)

Still doesn't handle pass-by-reference - but that's a problem even with 
variable numbers of params in LC, so I'll accept it for this case.

-- Alex.




More information about the use-livecode mailing list