Jon Lang wrote:
That saves a singlr character over Bag( ... ) and Set( ... ),
respectively (or three characters, if you find decent unicode bracket
choices). It still wouldn't be a big enough deal to me to bother with
it.
As well, my first impression upon seeing [! ... !] was to think
"you're negating everything inside?" That said, I could get behind
doubled brackets:
[[1, 2, 3]] # same as Bag(1, 2, 3)
{{1, 2, 3}} # same as Set(1, 2, 3)
<snip>
I prefer to have the mnemonic that {} means unordered and that [] means ordered,
so please stick to [] meaning arrays or ordered collections, an {} meaning
unordered collections, so set and bag syntax should be based around {} if either.
This said, I specifically think that a simple pair of curly braces is the best
way to mark a Set.
So:
{1,2,3} # a Set of those 3 elements
... and this is also how it is done in maths I believe (and in Muldis D).
In fact, I strongly support this assuming that all disambiguation eg with hashes
can be specified.
{a=>1,b=>2} # a Hash of 2 pairs
{:a<1>, :a<2>} # we'll have to pick a meaning
{} # we'll have to pick a meaning (Muldis D makes it a Set; %:{} is its Hash)
{;} # an anonymous sub or something
{a=>1} # Hash
{1} # Set
{1;} # anonymous sub or something
But keep that simple an let nesting work normally, so:
{{1}} # a Set of 1 element that is a Set of 1 element
{{a=>1}} # a Set with 1 Hash element
{[1]} # a Set with 1 Array element
[{1}] # an Array with 1 Set element
In certain cases, we can always still fall back to this:
Set() # empty Set
Hash() # empty Hash
Set(:a<1>) # if that's what we wanted
As for bags, well I think that is where we could get fancier.
But *no* doubling up, as we don't want to interfere with nesting.
Instead, it is common in maths to associate a "+" with set syntax to refer to
bags instead.
So, does Perl already ascribe a meaning to putting a + with various bracketing
characters, such as this:
+{1,2,2,5} # a Bag of 4 elements with 2 duplicates
+{} # an empty Bag, unless that already means something
So would the above try to cast the collection as a number, or take the count of
its elements, or can we use something like that?
But I would recommend something along those lines.
I suppose then if +{} works for bags we could alternately use -{} for sets but I
don't really like it.
-- Darren Duncan