List as a Tuple?

(imported topic written by gjeremia91)

Is there any way I can get a tuple from a list?..e.g. something like

color=blue

(“1”;“2”;“3”;“4”) as tuple[/color]

I’ve tried playing with "tuple string item of " but it doesn’t appear to work as I would expect:

color=blue

Q: tuple string item 0 of (“1,2,3,4”) [/color]

color=red

<—string with commas produces an error[/color]

color=blue

E: Singular expression refers to nonexistent object.

Q: tuple string item 0 of (“1”,“2”,“3”,“4”) [/color]

color=red

<—a tuple produces an error[/color]

color=blue

E: The operator “tuple string item” is not defined.

Q: tuple string item 0 of (“1;2;3;4”) [/color]

color=red

<-returns a single string[/color]

color=blue

A: 1;2;3;4 ( a string )

Q: tuple string items 0 of (“1”;“2”;“3”;“4”) [/color]

color=red

<—returns a list of strings[/color]

color=blue

A: 1

A: 2

A: 3

A: 4

[/color]

I’d expect something like:

color=blue

Q: tuple string item 0 of (“1”;“2”;“3”;“4”)

A: 1

Q: tuple string item 2 of (“1”;“2”;“3”;“4”)

A: 3

[/color]

I know I could accomplish this with:

( preceding text of first 
";" of it, preceding text of first 
";" of following text of first 
";" of it, preceding text of first 
";" of following text of first 
";" of following text of first 
";" of it, following text of first 
";" of following text of first 
";" of following text of first 
";" of it ) of concatenation 
";" of (
"1";
"2";
"3";
"4")

but that doesn’t appear to be the quickest or most elegant way.

(imported comment written by NoahSalzman)

What are you actually trying to do? What is the non-abstract use case?

(imported comment written by gjeremia91)

Noah, there are a few. One is IP Address comparison in a VERY LARGE decision tree. We currently map a CLASS A range to countries, unfortunately allocations are non-contiguous. We presely treat IPs as versions and have a large IF statement. I would like to be able to split the tree by evaluating at each octet to reduce the number of comparisons made at the endpoint. Worst case is ridiculously high for us, but I can do a tree-split and look at the class 2nd octet, 3rd octet then last, which would result in a minimum of 3 comparisons and a maximum of 258. This too can be done with treating strings as versions versions:

color=blue

(it > (“1.2.3.0” as version) and it < (“1.2.4.0” as version))[/color] works to determine if the 3rd octet is 3, but that’s not as neat or efficient as

color=blue

(it=“3”)[/color]. I had thought I may be able to use “major”,“minor”,“release” and “build” of version, but this appears not to work either.

I have other instances where I know I want the nth item from a predictable lists (generally lists in BigFix aren’t predictable, but they are when they come from "substrings separated by of ". in these cases it would be more efficient (and more readable) to say something like

color=blue

item 3 of ((substrings separated by “.” of “1.2.3.4”) as tuple) [/color]

(imported comment written by Bill.Ehardt)

For the IP addresses you can split it and use a tuple this way:

item 3 of ((preceding texts of first “.” of it,preceding texts of first “.” of following texts of first “.” of it,following texts of last “.” of preceding texts of last “.” of it,following texts of last “.” of it) of “192.168.1.100”)

(imported comment written by NoahSalzman)

Right, that is what he is trying to avoid. :slight_smile:

He knows how to do it, he just wants more direct/simpler language features to do it easier.

(imported comment written by Bill.Ehardt)

Sorry been a long day lol

(imported comment written by BenKus)

Add a space after the “,”…

For example:

q: tuple string items 1 of ((concatenation ", " of substrings separated by “.” of (it as string)) of subnet addresses of adapters of network)

Ben

(imported comment written by gjeremia91)

a space…really…lol…all it needed was spaces. Why spaces by the way? Why not just recognize any “,” or even:

color=red

Q: [/color]

color=blue

tuple string item using of [/color]?

(imported comment written by BenKus)

I think the idea was that when you cast a tuple “as string”, it naturally displays with spaces after commas for readability… the “tuple string item” inspector is supposed to be the reverse of the “tuple as string” inspector…

Ben