It’s fascinating: I’ve been using Pike for little over two years now and I have never really understood the Pike data type “multiset”. A multiset is the keys in an associative array – or mapping as they are called in Pike, or hash in Perl, or HashTable in C# – with the values left out. So if you have a Pike mapping that looks like
([ "key1" : 1, "key2" : 2, "key3" : 3 ]) a multiset of that would look like
([ "key1" : 1, "key2" : 2, "key3" : 3 ]) and an array would be
([ "key1" : 1, "key2" : 2, "key3" : 3 ]). Mappings and arrays I have used a lot, of course, but it was quite recently it came to me what the multiset is good for!
Lets say you have a function that takes a string as argument and that argument can have like 12 different values but you only want some action to take place if the value is one of three out of the twelve possibilities. In many languages that could be written like this Pike example:
I don’t know how many times I’ve written code like that. But here the Pike multiset really shines. This is how you could use the multiset:
I think that’s pretty nice. And that’s probably not the only thing the multiset is useful for.
While I’m at it, what about these nice syntactic sugar flakes of Pike:
The same in PHP
Even though I’ve used PHP for 7-8 years I still have trouble remembering in what order the arguments is supposed to come in the function call.