Page 1 of 1

"split as set" documentation mystifying

Posted: Fri Jan 22, 2021 3:15 pm
by aetaylorBUSBnWt
split variable {by | using | with} primaryDelimiter as set

The following is from the LiveCode 9.6.2 dictionary

If you use the as set form the split command converts the passed variable to an array with the keys being equal to the original list and the values being true.

For example, the following statements create an array:

Code: Select all

put "A apple;;B bottle;;C cradle" into myVariable 
split myVariable by ";;" and space 

# resultant array looks like this:
KEY    VALUE 
A    apple 
B    bottle 
C    cradle 
First, the example is not about using the "as set" version of the split command.
Second, how does LiveCode know what the original keys are?
The input can be a string, so the "keys" could be any number of characters "terminated" by some particular character.

Given the above, this means that "as set" is assuming some particular format for how the input is constructed.
Yet that format is NOT stated, it is assumed that the reader knows what it is.

What is this particular input format that is needed for the "as set" version of split.

Finally, what does "values being true" mean?

Oh, a final issue (possibly because the documentation was modified but not proofread entirely) - later in the Dictionary documentation for split it refers to the "second form" of split and then proceeds to describe the split by row and column. "Split as set" is the second type in the list of types of split shown at the top of the Dictionary entry for split.

Re: "split as set" documentation mystifying

Posted: Fri Jan 22, 2021 10:06 pm
by FourthWorld
The example provided related to the paragraph above the one about "as set", the section about using two delimiters.

The "as set" option simply splits on one delimiter, with the resulting array being a set of keys which are the values of the original list, where is element value is set to "true".

Thanks for bringing this documentation anomaly to our attention. I've filed a bug report for it:
https://quality.livecode.com/show_bug.cgi?id=23071

Re: "split as set" documentation mystifying

Posted: Fri Jan 22, 2021 11:42 pm
by aetaylorBUSBnWt
First, thanks for posting the bug.

From what you said, I believe the following:

The incoming variable may contain ONLY keys separated by the "primaryDelimiter".


If not, then how does the split command distinguish between a key and a value?

Re: "split as set" documentation mystifying

Posted: Fri Jan 22, 2021 11:51 pm
by FourthWorld
It doesn't need a supplied value, since the purpose of "split..as set" is to return an array where the value of all keys is "true".

Re: "split as set" documentation mystifying

Posted: Sat Jan 23, 2021 12:12 am
by bwmilby
The second form comment is correct. The first form allows specifying the delimiter(s) and the second uses the rowDelimiter and the columnDelimiter.

Re: "split as set" documentation mystifying

Posted: Sat Jan 23, 2021 12:27 am
by FourthWorld
bwmilby wrote:
Sat Jan 23, 2021 12:12 am
The second form comment is correct. The first form allows specifying the delimiter(s) and the second uses the rowDelimiter and the columnDelimiter.
Yes, the example itself is correct, but it relates to the form described two paragraphs above it, not the one immediately preceding it.

Re: "split as set" documentation mystifying

Posted: Sat Jan 23, 2021 1:52 am
by bwmilby
I think that “as set” is still part of the first form (where a delimiter is provided). I agree that the example should be moved. I’ll probably submit a PR on it this weekend unless someone else does it first.