Jump to content

A Tool For Writing LSL Scripts In Another Programming Language


Testicular Slingshot
 Share

You are about to reply to a thread that has been inactive for 931 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

19 hours ago, Mollymews said:

lists within lists.

 

15 hours ago, Profaitchikenz Haiku said:

Lists within lists is just about possible in LSL to one extra level, although horrible inefficient

My go-to solution for lists within lists is to have 2 lists: a data list, and an extents list

list a =
[
  0,
  [1,[3,[7,8],4,[9,a]]],
  [2,[5,[b,c],6,[d,e]]]        
];

becomes

list a = [0,1,3,7,8,4,9,a,2,5,b,c,6,d,e];
list a_extents = [0,0  1,7,  2,7, 3,4  6,7,  8,14, 9,14, 10,11,  13,14]; 

I've only used it on one extra level lists, but theoretically the idea is sound for arbitrary nested lists as above.

  • Like 1
Link to comment
Share on other sites

9 hours ago, Quistess Alpha said:

I've only used it on one extra level lists, but theoretically the idea is sound for arbitrary nested lists as above.

That's pretty close to how sparse arrays were set up.

I used them on systems that solved simultaneous Linear equations, several thousand of them at a go. The idea worked because once all the equations had been set up in the arrays, no further addiions or deletions were needed, if it had been otherwise then I suspect the system would have been to slow. As it was, on DEC Alphas, Solaris machines and HPux boxe it was a three-to-four hour run.

Link to comment
Share on other sites

11 hours ago, Quistess Alpha said:
list a = [0,1,3,7,8,4,9,a,2,5,b,c,6,d,e];
list a_extents = [0,0  1,7,  2,7, 3,4  6,7,  8,14, 9,14, 10,11,  13,14]; 

 

i am not getting how the values in a_extents relate to the data list

I get that there are 4 levels in the data, and that the spacing  in a_extents seems to denote a relationship between paired values. I am not understanding what they mean

Link to comment
Share on other sites

I think thy're the first and last elements of each sub-list? If so they allow set-inclusion and set-overlap which is quit a neat idea.

From memory a sparse array had an index that recorded the array index start for each row. There was no need to record the extent because that was obtained by the difference between it and the next row start index value.

Link to comment
Share on other sites

6 hours ago, Mollymews said:

i am not getting how the values in a_extents relate to the data list

I get that there are 4 levels in the data, and that the spacing  in a_extents seems to denote a relationship between paired values. I am not understanding what they mean

Each pair is a set of indexes into the data for use with llList2List.

(in my format I require/ very much encourage all elements to be at least double nested, so that looping through all the indexes doesn't skip any elements, and redundant sub-lists are disallowed, I.E, you can't have [1,[[2,3]]] as that would be the same as [1,[2,3]]  extents list [0,0,  1,2, 1,2] would work . . .you could also have overlapping lists, like [1,[2,3,(4,]5,6),7] which don't really work with normal list notation. extents [1,3,  3,5 ] )

Quote
list a =
[
  0,
  [1,[3,[7,8],4,[9,a]]],
  [2,[5,[b,c],6,[d,e]]]        
];

becomes

list a = [0,1,3,7,8,4,9,a,2,5,b,c,6,d,e];
list a_extents = [0,0  1,7,  2,7, 3,4  6,7,  8,14, 9,14, 10,11,  13,14]; 
  • first pair is 0,0 I.E, the first element is a singleton.
  • next pair is 1,7, so [1,3,7,8,4,9,a] is a sub list.
  • next pair is 2,7, so [3,7,8,4,9,a] is a sub list, and because 2 is between 1 and 7, and 7 is between 1 and 7, it is also a sub list of the first sub list.
  • 3,4 corresponds to [7,8] in the data list, which is similarly a sub list of lists 2,7, and 1,7.
  • etc etc.

Adding or removing data at some index simply requires adding or subtracting 1 to all extents greater than that index. although, you do need to be careful where you want to put an element at the edge of a sub-list (for complex highly nested lists, might be wise to add buffer elements at the ends of the data, to make complex insertions easier.).

  • (data) [ [0,1,2],[3,4,5],[6,[7,8]]] (add b before 3)->  [ [0,1,2],[b,3,4,5],[6,[7,8]]]
  • (extents) [0,2, 3,5,  6,8, 7,8] (add b before 3) -> [0,2, 3,6,  7,9, 8,9] (+ if >3)
  • (data) [ [0,1,2],[3,4,5],[6,[7,8]]] (add a after 2)->  [ [0,1,2,b],[3,4,5],[6,[7,8]]]
  • (extents) [0,2, 3,5,  6,8, 7,8] (add a after 2) -> [0,3, 4,6,  7,9, 8,9] (+ if >=2)
Edited by Quistess Alpha
  • Like 1
Link to comment
Share on other sites

3 hours ago, Quistess Alpha said:

 

  • first pair is 0,0 I.E, the first element is a singleton.
  • next pair is 1,7, so [1,3,7,8,4,9,a] is a sub list.
  • next pair is 2,7, so [3,7,8,4,9,a] is a sub list, and because 2 is between 1 and 7, and 7 is between 1 and 7, it is also a sub list of the first sub list.
  • 3,4 corresponds to [7,8] in the data list, which is similarly a sub list of lists 2,7, and 1,7.
  • etc etc.

Adding or removing data at some index simply requires adding or subtracting 1 to all extents greater than that index

 

thanks for the explanation. Your indexing method is n-dimensional like you said. This is really cool. I like it a lot

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
On 10/24/2021 at 12:28 AM, Mollymews said:

i looked it up, because I am nosey

from the Fortran examples I found, seems a sparse array is a n-dimensional matrix with memory only taken up by used elements

LSL equivalent is as you say lists within lists. Like:

list a =
[
  0,
  [1,[3,[7,8],4,[9,a]]],
  [2,[5,[b,c],6,[d,e]]]        
];

i thought it was more like a tree because 'list a' is a binary tree. But I can see now that a tree is only a subset view of a n-dimensional sparse matrix

i did read also that Fortran has quite a lot of helper functions/methods to quickly address/traverse the sparse array

a answer on stackoverflow, was the most helpful in my understanding of this

https://stackoverflow.com/questions/62255387/sparse-array-in-fortran

Fortran sparse arrays are pretty cool. And I can see how extremely useful they are to engineers and scientists who have heaps of variable data to model

Wow, that gave me a flashback to the "good old days" of Lisp...and not really a good one.  :)

 

"( i am a list) (a ( a b c) d e fgh) (father tom ( susan bill joe)) (sun mon tue wed thur fri sat) ( )"

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 931 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...