Please, how can I overcome the “(left/right) operand of ‘&’ must be singular” errors resulting from:
(items 0 of (("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED"))) as string) & ((items 1 of (("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED")))) as string)
It’s not entirely clear to me what you’re trying to do, but I will try to answer.
I think you’re asking about how to combine/concatenate a tuple with the ‘&’ operator.
Given the relevance you provided, the tuple itself is the following:
(("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED")))
The ‘&’ operator, as the error you received suggests, requires singular results.
When we have a list of plural results, and we want to iterate over them one at a time (i.e. to treat them singularly), we can do so with the following forms:
(it) of <object>
OR (it) of <property> of <object>
(you can see an example of this within the tuple itself by the way where the name and free space of drives is being concatenated)
With tuples, we can extract specific portions using item. Combining these then, one option might be:
(item 0 of it & item 1 of it) of (("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED")))
Correct, I was practicing concatenation and trying to figure out how to do so with plurals.
When you can make time, could you please help us understand more clearly the mistake in logic with the original Relevance and the attempted work towards a solution which follows? I feel there’s a fundamental misunderstanding here regarding how to accomplish the iteration of results but can’t quite put my finger on it…
Q: (items 0 of ((“Excercise 18: “), ((name of it &” - “& (free space of it / 1024 / 1024 / 1024) as string &” GB”) of drives whose (type of it = “DRIVE_FIXED”))) as string), ((items 1 of ((“Excercise 18: “), ((name of it &” - “& (free space of it / 1024 / 1024 / 1024) as string &” GB”) of drives whose (type of it = “DRIVE_FIXED”)))) as string)
A: Excercise 18: , C: - 117 GB
A: Excercise 18: , D: - 425 GB
A: Excercise 18: , C: - 117 GB
A: Excercise 18: , D: - 425 GB
T: 0.668 ms
With scenarios like these, I find that it can help to play with simpler examples. Let’s start with a plural result (one easy way to create plural results is to separate some individual results with semi-colons):
Q: ("a";"b";"c")
A: a
A: b
A: c
I: plural string
So, we can see that the above example returns a plural string. We can confirm this by asking for the number of results with something like:
Q: number of ("a";"b";"c")
A: 3
I: singular integer
Now, we know that we can’t use the concatenation operator with a plural result (we’ll receive an error telling us so):
Q: ("a";"b";"c") & "!"
E: A singular expression is required.
So, we need to handle each result individually, or iteratively. And this is where the form I mentioned above comes into play:
Q: (it) of ("a";"b";"c")
A: a
A: b
A: c
I: plural string
This statement essentially translates to something like: return the object/property to the right of ‘it’ (and if the object/property is a plural or list of results, return them individually, one at a time, in order).
To validate that the ‘it’ allows us to handle each result individually, we can try to count the number of ‘its’:
Q: (number of it) of ("a";"b";"c")
A: 1
A: 1
A: 1
I: plural integer
Unlike when we previously counted the number of results, here, we can see that the number of results is individually counted. Given that we have a single result per answer, we can now use the concatenation operator:
To try to show why the the original form (or one of them at least as I think there are a few), didn’t quite work as desired, let’s break it down into smaller chunks.
This itself is a tuple (i.e. there are 2 ‘things’ that are tupled together):
(items 0 of (("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED"))) as string)
AND
((items 1 of (("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED")))) as string)
The first thing in the tuple references items 0 of another tuple, and the second thing in the tuple references items 1 of another tuple (and actually, it’s the same tuple). So, let’s break it down further:
(("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED")))
This itself is another tuple combining a string ("Excercise 18: "), and another string (potentially a list or plurals) corresponding to the name and free space of fixed drives.
Q: (("Excercise 18: "), ((name of it &" - "& (free space of it / 1024 / 1024 / 1024) as string &" GB") of drives whose (type of it = "DRIVE_FIXED")))
A: Excercise 18: , C: - 169 GB
A: Excercise 18: , G: - 160 GB
A: Excercise 18: , R: - 5 GB
I: plural ( string, string )
Let’s create a simpler example of the above.
Q: "!",("a";"b";"c")
A: !, a
A: !, b
A: !, c
I: plural ( string, string )
“!” represents "Excercise 18: ", and “a”, “b”, and “c” represent the drives and their free space.
From this tuple, if we ask for items 0 or items 1, we’ll get the corresponding parts of the tuple (I often think of them as arrays or matrices):
Q: items 0 of ("!",("a";"b";"c"))
A: !
A: !
A: !
I: plural string
Q: items 1 of ("!",("a";"b";"c"))
A: a
A: b
A: c
I: plural string
We can’t concatenate these 2 (since they’re plurals):
Q: items 0 of ("!",("a";"b";"c")) & items 1 of ("!",("a";"b";"c"))
E: A singular expression is required.
And if we look back at our original form, it was creating a tuple of a tuple, which is not unlike multiplying arrays (which I don’t believe was the desired or intended result). This means that we’re asking relevance to combine the 2 tuples in all of the possible ways, leading to something like:
Q: items 0 of ("!",("a";"b";"c")), items 1 of ("!",("a";"b";"c"))
A: !, a
A: !, b
A: !, c
A: !, a
A: !, b
A: !, c
A: !, a
A: !, b
A: !, c
I: plural ( string, string )
So, rather than combining the tuples together, we can ask for specific items from the tuple individually, and combine them with other items from the tuple:
Q: (item 0 of it & item 1 of it) of ("!",("a";"b";"c"))
A: !a
A: !b
A: !c
I: plural string
(and this is essentially a simplified version of what I had shared above).
“a”, “b” and “c” are some of my best companions. I really like your use of “!” as it draws the eye to “the important part”
I may have to borrow some of these simplified examples to add to my own teaching techniques.
Another teaching trick: use “dog” instead of d, to “show” that things are not limited to single letters, but without overly complicating the readability.
Apologies for the delayed reply (I have had little free time recently), and MANY Thanks!! I will be enthusiastically studying these responses very soon and greatly appreciate your time and effort! Ditto to all our other contributors