Difference between revisions of "Talk:LlList2ListStrided"
Pedro Oval (talk | contribs) (→No exclusion range: who cared, to start with?) |
|||
Line 289: | Line 289: | ||
::More than that nobody ever tested, I'd say that most likely, nobody ever ''cared about'' the exclusion range features of this function. Or of llListReplaceList, for that matter. Only a little few care about it in llList2List and llDeleteSubList or their string counterparts, and mostly to make delete act like extract or vice versa, while making it behave in some corner cases. --[[User:Pedro Oval|Pedro Oval]] 19:18, 23 June 2014 (PDT) | ::More than that nobody ever tested, I'd say that most likely, nobody ever ''cared about'' the exclusion range features of this function. Or of llListReplaceList, for that matter. Only a little few care about it in llList2List and llDeleteSubList or their string counterparts, and mostly to make delete act like extract or vice versa, while making it behave in some corner cases. --[[User:Pedro Oval|Pedro Oval]] 19:18, 23 June 2014 (PDT) | ||
:::Wait, is something screwy with llListReplaceList docs too? -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 23:03, 23 June 2014 (PDT) |
Revision as of 22:03, 23 June 2014
Having some problems with this one, the page says:
"To get every second element in a "collection of data" in a strided list:" <lsl>llList2ListStrided(llDeleteSubList(src, 0, 0), 0, -1, 3);</lsl>
However that does not seem right, the last stride 3 should be a stride 2.
With an input list:
0.250000,a,0.250000,b,0.250000,c,0.250000,d
and using stride 3 instead of stride 2, I get:
a,0.250000,d
Using: <lsl>llList2ListStrided(llDeleteSubList(src, 0, 0), 0, -1, 2);</lsl> with a stride of 2 at the end instead, I get the expected result:
abcd
It makes sense to me: we are returning just the second element, so there is no need for a stride of 3, but rather a stride of 2 and the first element deleted.
I have changed it on the page, if I am wrong, please change it back.
Kira Komarov 07:11, 8 January 2012 (PST)
- There are a few problems with the article:
- A sample value of src was not provided.
- A description of src was not provided.
- The example fails to correlate the value 3 with any requirement for the structure of src or that it is important.
- For your example, using a strided list where the stride is 2 (and not 3) you need to set the llList2ListStride stride parameter as 2 (and not 3).
- Since fixing the example to match your usecase isn't going to help anyone with a say a stride of 4 we need to fix the example as to remove all underlying confusion. -- Strife (talk|contribs) 11:30, 8 January 2012 (PST)
Uhm, no...
Why do I even bother... Perhaps Linden should just put my account on hold again and put me out of my misery... Too many mobsters, I tell ya...
There are a few problems with the article
First, I have no clue what you are talking about Strife, you mean the src in my example? Or the src on the page? Since you want a "sample", I assume you are talking about the src in my example. Although I do say "with an input list":
0.250000,a,0.250000,b,0.250000,c,0.250000,d
So, I am not sure what you are talking about. What example? The example on the article page was broken (by Chaz Longstaff apparently at 11:06, 13 July 2008). That one?
For your example, using a strided list where the stride is 2 (and not 3) you need to set the llList2ListStride stride parameter as 2 (and not 3).
Thank you! Wait… Didn't I just say that in my first question? o.O
No, you need to use 2 instead of 3 for every example where you want to get every second element in a strided list.
Here is why:
- takes a paper out, puts a fist in her cheek and sighs deeply...*
Let S be an infinite abstract set of elements, such that:
S = ( s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 ... )
where s0, s1, s2, … are elements of the set S.
Let us assume that the set S is given by:
S = { i | i=[0, inf) }
where i is a number in the interval [0, inf).
We proceed to prove by induction that S gives us that set:
The base-case, for i=0:
S_{0} = ( s0 )
For i=1:
S_{1} = ( s1 )
For i=2:
S_{2} = ( s2 )
Which seems correct, thus let i->i+1:
S_{i+1} = { i+1 | i=[1, inf) }
However, since lists in computer science are indexed starting from zero, we subtract one from the indexer i, thus obtaining:
S_{i} = { i | i=[0, inf) }
which is exactly what we had to prove.
For kicks, let's run a few consistency checks:
S = ( s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 ... ) S_{0} = ( s0 ) S_{1} = ( s1 ) S_{2} = ( s2 ) S_{3} = ( s3 ) S_{4} = { s4 ) ...
Now, let S' be a new infinite abstract set, which will consist of every second (2-nd) element of the original set S:
S'= { 2i-1 | i=[0, inf) }
We proceed to prove by induction that S' gives us that set:
The base-case, for i=0:
S' = ( φ ) or, the element at index inf-1, in case of LSL wrap-around lists. This is why the code uses llDeleteList() to delete the first element.
For i=1:
S' = ( s1 )
For i=2:
S' = ( s3 )
Which seems correct, thus let i->i+1:
S'_{i+1} = { 2(i+1)-1 | i=[1, inf) }
However, since lists in computer science are indexed starting from zero, we subtract one from the indexer i, thus obtaining:
S'_{i} = { 2i-1 | i=[0, inf) }
which is exactly what we had to prove.
For kicks, let's run a few consistency checks:
S_{1} S_{2} S_{3} S_{4} | | | | | | | | . . . . S = ( s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 ... ) S_{0} = ( φ ) S_{1} = ( s1 ) S_{2} = ( s3 ) S_{3} = ( s5 ) S_{4} = { s7 ) ...
One thing to note is that 2k+1 gives us odd numbers (2i+1 is what we would have gotten if we would not had subtracted one from the indexer):
k = 0 => i = 1 k = 1 => i = 3 k = 2 => i = 5 k = 3 => i = 7 ...
and 2k gives us even numbers:
k = 0 => i = 0 k = 1 => i = 2 k = 2 => i = 4 k = 3 => i = 6 ...
The set of (positive) integers N is defined by an union between the set of odd and even numbers:
E = { 2k | k = [0, inf) } set of even numbers O = { 2k+1 | k = [0, inf) ] set of odd numbers N = E U O
which gives us a set N (the natural number set) with every positive number without repetitions up to infinity. The same can be applied to the whole integer set Z, for negative numbers as well.
That is, by combining the few examples we have above, we get:
0, 1, 2, 3, 4, 5, 6, 7...
Similarly, another thing to note, is that the base-case k=0:
S'_{2 * 0 - 1} = S_{-1} = ( Φ )
gives us the empty set, or infinity-1 in LSL terms and that is why we delete the first element:
llList2ListStrided( llDeleteSubList(l, 0, 0) , 0, -1, 2); ^ | right here
Hence: <lsl> list S' = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 2); </lsl> is correct, instead of:
<lsl> list S' = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 3); </lsl> with '3, as it was written before on the wiki.
Example: <lsl> default {
state_entry() { list l = [0,1,2,3,4,5,6,7,8,9,10,11,12]; list s = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 2); llOwnerSay(llDumpList2String(s, " ")); }
} </lsl>
Output:
Object: 1 3 5 7 9 11
Counter-example, as the page was written before: <lsl> default {
state_entry() { list l = [0,1,2,3,4,5,6,7,8,9,10,11,12]; list s = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 3); llOwnerSay(llDumpList2String(s, " ")); }
} </lsl>
Output:
Object: 1 4 7 10
Kira Komarov 13:11, 22 January 2012 (PST)
- I'm not seeing the disagreement here. If we have a list containing 3 strides with a width of 3 that are all [1,2,3] so the list is [1,2,3,1,2,3,1,2,3], llList2ListStrided(llDeleteSubList([1,2,3,1,2,3,1,2,3], 0, 0), 0, -1, 3) == [2,2,2]. Second element of each stride. If [2,2,2] isn't a list of the second elements of each stride (of 3) of [1,2,3,1,2,3,1,2,3], what is it? -- Strife (talk|contribs) 18:09, 22 January 2012 (PST)
Confusion in Notes Section
I find the wording in the notes section (under Ranges & Indexes ) to be a bit confusing. The reference to the "range operated on" is not clear. I am not sure what would be better but it should be made clear that they are referring to the collection of entries in a single stride. For example, the reference to the variable start as indicating the range to start on should say that it indicates which set of strides the operation begins.
Confusing spec
Looking at the examples we see this: <lsl>list mylist = [0,1,2,3,4,5,6]; list result_a = llList2ListStrided(mylist,0,-1,2); //start at first item in list, go to the end, return every 2nd item //result_a == [0,2,4,6]
list result_b = llList2ListStrided(mylist,1,-1,2); //start at second item in list, go to the end, return every 2nd item //result_b == [2,4,6]</lsl>
Unfortunately, result b is NOT what I would expect, I would expect [1,3,5]. In fact, I don't see a way to get the odd elements. I've had to resort to this: <lsl>list mylist = [0,1,2,3,4,5,6]; list result_a = llList2ListStrided(mylist,0,-1,2); //start at first item in list, go to the end, return every 2nd item //result_a == [0,2,4,6]
list result_b = llList2ListStrided(llDeleteSubList(mylist,0,0),0,-1,2); //start at second item in list because I deleted the first, go to the end, return every 2nd item //result_b == [1,3,5]</lsl>
Perhaps we need an llList2ListStridedNotBraindead?
09:36, 25 February 2012 (PST)
- I totally agree with you, this function is counter intuitive*. The design is strange. I'll submit a feature suggestion for a new function, not sure what to call it. -- Strife (talk|contribs) 17:37, 25 February 2012 (PST)
No exclusion range
When start is past end, the function returns the same as if start were 0 and end were -1 (the whole list range, strided) e.g. llList2ListStrided([0,1,2,3,4,5,6,7], 4, 2, 2) returns [0,2,4,6]. I don't know how to modify the text to correct that. --Pedro Oval 19:16, 21 June 2014 (PDT)
- Well that is no good. I'm not sure if that should be reported as a bug or not. Probably not? Nobody ever tested the exclusion range features of this function I guess. I'll tweak the template and the article. I'll leave a space in the template for the new text but I have to head to bed instead of fill it. -- Strife (talk|contribs) 22:59, 21 June 2014 (PDT)
- Err conditionals will need to be added to Template:LSL_Function/negative_index/range, I'll see if I have time tomorrow. -- Strife (talk|contribs) 23:09, 21 June 2014 (PDT)
- More than that nobody ever tested, I'd say that most likely, nobody ever cared about the exclusion range features of this function. Or of llListReplaceList, for that matter. Only a little few care about it in llList2List and llDeleteSubList or their string counterparts, and mostly to make delete act like extract or vice versa, while making it behave in some corner cases. --Pedro Oval 19:18, 23 June 2014 (PDT)