Querying lists of property lists

Are there any samples showing how we query lists of property lists?

If i use the following, it will put the content of all propety lists in the list into the debug window:
put each item in listOfPropertylists

Give an a property list of

{property1:value1, property2:value2}

It feels like we should be able to use somethign likethe following, but i cant quite seem to get the syntax right:

put each item in listOfPropertylists where item's property1 is 1

I feel i must be close but all i get in the debug window is
[]

ANd then to take this concept further, instead of outputting the entire item, output just 1 property of the item:
put each item's property1 in listOfPropertylists

(it doesnt seem to be possibel to query aproperty in conjunction with “each”)

many thanks

Yes, you are very close,

put each item in listOfPropertylists where each's property1 is 1
or
put each item in listOfPropertylists where each.property1 is 1

1 Like

An prime example of how to keep an idiot in suspence :smiley:

Sorry! I went to get a newline, but it submitted instead

Thanks for the reply / edit :slight_smile:

I am still getting
[]

as my return.

i am building my list of properties like a dictionary:

put {property1:"test1", Property2:1} into testProperty
set listOfPropertyList's[(testPropery's property1)] to testProperty

edit:
WHo’s crazy idea was it to make ctrl+enter a send message short cut?

Yeah, thats what happened to me I think.

are you looking for something like this?

put {property1:"test1", Property2:1} into testProperty
put {property1:"test3", Property2:2} into testProperty2
put testProperty into listOfPropertyList
insert testProperty2 into listOfPropertyList

put the property1 of each item of listOfPropertyList

Kind of.

if you do put and insert the items go into the list unkeyed.

I am building a keyed dictionary that gets updated so i use:

		if listOfPropertyList's keys contains testProperty's property1
			add 1 to the property2 of (listOfPropertyList's[(testProperty's property1)] )

		else
			set listOfPropertyList's [(testProperty's property1)] to testProperty

		end if

after the disctionary is built it hands it offf to the calling function for specific processing based on the testcase

There may be some confusion here about what your data structure is. The fact that you are accessing listOfPropertyList's keys tells me that listOfPropertyList is actually a property list, not a list (because a list doesn’t have keys). Also, your use of square brackets in the code you posted is confusing and likely to cause problems.

The code Anne posted generates a list of property lists, which will work nicely with an each expression. Working with a property list of property lists will be more awkward, I think.

The use of square brackets came from a post of a few years ago, in reference to using variables to access properties - is this syntax depercated in favor of another now?

If the “list” is unkeyed, this makes it much more akward to populate / update the dictionary entries.

Looking back at athe article in question it states “enclose in parenthasis” but i think maybe the EFP IDE autoconverted them to square at one point and i hadn’t noticed, assuming from that point forward that was the format needed. I’m editing my code to see the effect of just having “(” and “)”

I think i managed to get it to do what i wanted using this:

put the property2 of each item of values of each item in listOfPropertyList

It might not be the comfiest line of code ever to read, but this is at a framework / helper level that gets consumed by more test specific scrpits so i’m less concerned about every-day re-typing of it.

Really appreciate the input and assistance

best regards

paul

Okay, that makes sense. Enclosing a value in [ ] turns it into a list of one item. A quick test shows me that SenseTalk is accepting a single-value list as a key in this case, so the brackets aren’t doing any harm, other than making your code less readable.

Since you want to work with a nested property list rather than a list of property lists, then you may find it easier to work with the keyForValue function (or keysForValue if there may be more than one property with the same value) rather than using an each expression. Or just write a simple repeat loop:

repeat with each [key,val] in plistOfPropertyList
    if val's property1 is 1 then insert val into selectedPlists
end repeat
put selectedPlists

Off the back of this, not specifically linked to lists, but I am testing code in the DO command-line tool in the running script window - if an exception occurs when executing a line of code, would you expect in-memory variables to be cleared?

I find all my data is queryable, up to the point i make a mistake than it all disappears, though the loclas window implies it is all still in memory (maybe a lack of update to reflect the loss of data?)

image

thanks
paul

No. Offhand, I wouldn’t expect that command or the error it gave to affect the contents of your rslt variable. But it’s an unusually complex each expression, so you may have run into an obscure bug.
What you probably want is something like:
put the count of each item of values of each item in rslt where true where the count of each is greater than cutoff

Doug,

That was perfect, thank you… I was just about giving up for the night else i would have a keyboard imprint in my face through repeated hammering… :smiley: