In one of my scripts, I have a property list with 25 items. I have another script with 25 other items.
When I add script B into script A, I check the number of items in script A. Insted of the expected sum of 50, I get the result of 25.
However, when I output the value in the list, I see all 50 items.
set listA = (... ) -- 25 items
set listB = (... ) -- 25 MORE items
add the properties of listB to listA -- I expect a sum total of 50 items
put the number of items in listA -- I get only 25 items
put listA -- When I view the contents, I see all 50 items!!
Any idea what might cause this?
I think it’s a bug. I tried this:
set listA = ( a:1,c:3 )
set listB = ( b:2, d:4 )
put number of items in listA
put number of items in listB
add properties of listB to listA
put number of items in listA
And here is the result:
2 // -> I Expect 4 here!
(a:“1”, b:“2”, c:“3”, d:“4”)
On the output that I commented, I expect 4.
I think the confusion here comes from the fact that SenseTalk has three different kinds of “lists”, and the word “item” only applies to two of them.
A property list isn’t really a “list” of items, it’s a collection of properties, each consisting of a key and a value. So what you really want is to ask for the number of properties (SenseTalk also allows you to ask for the number of keys or values, if that feels more natural to you):
put the number of properties in listA -- you should get 50 this way
put the number of keys in listA -- or like this
put the number of values in listA -- or this
Asking for the number of “items” in something will tell you either the number of “list items” (if the value is an actual list), or the number of “text items” (separated by commas, or whatever the itemDelimiter is set to) if the value is not a list. In your case, listA was not a list, so SenseTalk converted it to a text representation in order to count its text items (which, unfortunately, was not what you wanted!). You could prevent it from doing this by explicitly asking for “list items” instead of “items” – this would report that listA contained 1 list item, since any non-list value can be treated the same as a list of 1 item.
I hope this helps to clarify the situation.
Pardon me for jumping in on HarmoniaTester’s question, but this does not make sense to me. I understand that maybe I ask for the number of properties wrong and I can accept that, but the explanation of what SenseTalk is doing behind the scenes in my example doesn’t make sense to me.
listA has become (a:“1”,b:“2”,c:“3”,d:“4”)
so when I ask: put number of items of listA
you say that SenseTalk is making a string representation of listA. In my mind, this is going to be either: ‘(a:“1”,b:“2”,c:“3”,d:“4”)’ (all one string) or ‘a:“1”’,‘b:“2”’,‘c:“3”’,‘d:“4”’ (four strings)
so number of items in my two interpretations is 1 or 4, respectively. But I’m getting a result of 2.
You’re right – THAT is a bug. After playing with it briefly I discovered that if you delete the first command that displays the number of items in listA, you will get the correct answer. This bug appears to be related to SenseTalk cacheing some information about the text items in listA the first time you ask, and not resetting that information when the add properties command is executed, so it assumes that listA still has the original number of text items.
My previous explanation is still correct, however, as you will see from this example:
set plist to (a:1, b:"2,345")
put the number of items in plist -- not what you want!
put the number of values in plist
Thanks for pointing out the bug. We’ll try to get it fixed for the next release.