Brandon S Allbery KF8NH wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 11/7/10 23:19 , Jon Lang wrote:
>> 1 -- 2 -- 3
>>
>> Would be a Bag containing three elements: 1, 2, and 3.
>>
>> Personally, I wouldn't put a high priority on this; for my purposes,
>>
>> Bag(1, 2, 3)
>>
>> works just fine.
>
> Hm. Bag as [! 1, 2, 3 !] and Set as {! 1, 2, 3 !}, with the outer bracket by
> analogy with arrays or hashes respectively and the ! having the mnemonic of
> looking like handles? (I have to imagine there are plenty of Unicode
> brackets to match.)
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)
AFAIK, this would cause no conflicts with existing code.
Or maybe these should be reversed:
[[1, 1, 2, 3]] # a Set containing 1, 2, and 3
{{1, 1, 2, 3}} # a Bag containing two 1s, a 2, and a 3
{{1 => 2, 2 => 1, 3 => 1}} # another way of defining the same Bag,
with explicit counts.
OTOH, perhaps the outermost character should always be a square brace,
to indicate that it operates primarily like a list; while the
innermost character should be either a square brace or a curly brace,
to hint at thye kind of syntax that you might find inside:
[[1, 1, 2, 3]] # a Set containing 1, 2, and 3
[{1, 1, 2, 3}] # a Bag containing two 1s, a 2, and a 3
[{1 => 2, 2 => 1, 3 => 1}] # another way of defining the same Bag,
with explicit counts.
Yeah; I could see that. The only catch is that it might cause
problems with existing code that nests square or curly braces inside
of square braces:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] # fail; would try to create Set
from "1, 2, 3], [4, 5, 6], [7, 8, 9"
[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # creates 3-by-3 array
...so maybe not.
It should never be more than two characters on either side; and
there's some benefit to using square or curly braces as one of them,
to hint at proper syntax within. Hmm... how about:
|[1, 2, 3]| # Set literal
|[1=>true, 2=>true, 3=>true]| # technically possible; but why do it?
|{1, 1, 2, 3}| # Bag literal
|{1=>2, 2=>1, 3=>1}| # counted Bag literal
--
Jonathan "Dataweaver" Lang