AppendDictionaryValue adds "=" suffix to key

Given the following code:

Let aDict=InitializeDictionary()
AppendDictionaryValue aDict, "myKey", ",", "myValue"

DisplayData DumpDictionary(aDict)

The expected output should be:


However, it is actually:


Note the [=] after the key.

Running PanoX b32 (4226)

Perhaps you want to use setdictionaryvalue instead of appenddictionaryvalue. It will add a new entry or replace an existing value if it finds a matching key.

Dumpdictionary always outputs the dictionary with a = sign between the key and the value.

Appenddictionaryvalue will modify an existing dictionary value if it finds the key. It does this by adding the value to the dictionary and inserting the separator. As you found, if it does not find the key, it creates a new key/value pair, and inserts the separator at the front of the value. And you can change the = sign with the replace( function. Here is an example:

Let aDict=InitializeDictionary("myKey","MyValue")
appenddictionaryvalue aDict, "myKey",",","myValue2"
alertsheet replace(DumpDictionary(aDict),"="," is ")

The output will be:

myKey is MyValue,myValue2

Dang. I thought I deleted this post! Haha :smiley:

You’re right. I need to start with a “SetDictionaryValue” if the key doesn’t exist … and then append if it does.

Thanks for taking the time to respond … my apologies for wasting your time, Tom!

I just learned something new. I did not realize that you could leave off the parameters to this function to create an empty dictionary. As an programmer with experience in other languages, I can see why you would think that, and you were right! This is not documented, and I don’t know if I ever intended this or tested it. But it works.

By the way, there is another way to make an empty dictionary:

Let aDict=""

This is leftover from Panorama 6, where dictionaries were implemented as text with special tags in them. Now dictionaries are opaque binary values, but Panorama X does have a special case that allows it to recognize "" as an empty dictionary. But using initializedictionary() is just as good, maybe better since it is more clear what the intent is.

You do, but that kind of sucks. Starting with the b33 release, you won’t need to do that anymore, you can just append, append, append. Here’s the code change I just committed.

Here’s an example:

CleanShot 2023-01-27 at 00.30.47@2x

Here’s the linstrumentation log when this runs:


mdj, I thought you had deleted it too. I started writing my reply but when I tried to post it, it did not work and then I could not find your original. After a while, and I don’t know what I did, it came back and there was your original and my reply. In the meantime, the color of your entire entry changed to a peach color; I guess now that means it had been deleted. Anyway, it was not a waste of time, because I learned in the process exactly the difference between setdictionaryvalue and appenddictionaryvalue.


(I had hoped you might consider doing that … :-))