Regarding to keys of property list

I got some key-values from a file, and wanted to convet them to a property list through a repeat loop. But the key is variable, how can I put the varialbe to a key of property list?
e.g.
put “a1” into a --a is a variable
add properties (a:“1”) --I want a1 as the key not a.

You need to use the “do” command, which executes any string representing syntactically correct SenseTalk code:

put "goat" into a
do "set myList." & a && "to" && quote & "cheese" & quote
put myList -- outputs (goat:"cheese")

So you need to construct a string as an argument to the “do” command that references your variable and sets the desired value to the key.

Actually, SenseTalk allows you to use an expression enclosed in parentheses in place of a literal key name in most places, so this should work for you:

set myList.(a) to 1

By enclosing ‘a’ in parentheses here, it is treated as an expression (just a variable name in this case) that supplies the name of the property, instead of accessing the property named ‘a’.

This trick can also be used directly in a property list expression, so if you want to use the “add properties” command to only set the property if it’s not already set, you could do it like this:

add properties ((a):1) to myList

Thanks, Doug. I’ll leave my post up as an example of how “do” works, but obviously Doug has provided the appropriate way of dealing with this situation.

Thank you Doug for this example. I have been using the Do command like Matt showed for quite a while now, but the List.(a) is a nice clean way to perform this task.

I have searched the eggplant users guide for this expression, but I could not find it. This might be a good one to add to the Sense Talk guide in the section on property lists.

Thanks for the suggestion. This is documented in the latest version of the SenseTalk Reference Manual in the chapter on Expressions, under the topic “Uses of Parentheses”, subheading “Forcing Evaluation as an Expression”. I thought it was mentioned somewhere in the section on property lists too, but I don’t see it so I think it’s a good idea to add something there.