dict get

withakay's icon

Despite what it says in the help, when you send 'get mykey' to [dict mydict] you get the key and the value out of the second output (not just the value). Usually I don't want to know the key so I have to loose it somehow, usually by using [route mykey].

I feel like there should be a better way to do this, is there?

gorecki's icon

That's perfectly acceptable. You can also do "unpack s i" and get the second outlet. That would allow to have different keys and not worry about route.

withakay's icon

True, but I still have to think about if I need [unpack s i], [unpack s f] etc.

taking the right output from [zl.slice 1] is the best I have come up with so far.

Shame you can't pass the name of the dict an an argument to [dict] could easily make an abstraction then.

It is a silly small point but being able to do something like [dictutil mydict get mykey] and jut get the value would be ideal, 1 object not 3 much less visual noise in the patch.

The fact that dicts now exist at all is really great, so I will stop moaning and keep patching.

eleven_t's icon

I usually put a message object with $2 or $2 $3 if the key contains another dict ;]

Charles Matthews's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I'm using the following a fair bit as an abstraction:

same result as zl slice but might be handy to be able to route some other keys while you're at it.