Page 1 of 1

Combine array in key order

Posted: Wed Feb 04, 2015 9:36 pm
by RobertC
combine array at present gives unexpected results. Extending the command to make it look like the sort command would be useful.

Example: I had to mark up each line of a long text with html tags, depending on the content of the line and also the contents of the two adjacent lines. The original algorithm became very slow after the introduction of unicode. The time taken was reduced by a factor of 200 by first using split to get an array of lines, then doing the markup using the array. However, using combine to put the lines back together into a single marked-up text produced unexpected results (as is in fact documented in the Dictionary: the order in which the elements are combined depends on internals of array handling).
It was not possible to sort the lines of text after the combine operation.

Proposal:
there is a useful form of the sort command:
sort lines of tData descending numeric by item 1 of each
a similar clause could help in many cases of combine:
combine myArray ascending numeric
would have given the desired result.
Perhaps this should even be the default: if the keys are numbers then combine should produce a result corresponding to using the keys in ascending order.

LiveCode's aim of programming in a natural language has as a corollary that its commands should produce as few unexpected results as possible.

Re: Combine array in key order

Posted: Wed Feb 04, 2015 10:13 pm
by FourthWorld

Re: Combine array in key order

Posted: Fri Feb 06, 2015 10:53 am
by RobertC
Thanks Richard.