-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Dict comprehensions and typed Dicts -- alternative version (changes Dict literal notation) #1478
Conversation
Mostly in favor of this, but seeing |
Just when I kind of got almost more or less somehow used to it!! So, I will now remove it; this will leave unsolved the issue of building an empty Warning: wild speculation/random babbling ahead A possible concern with this general framework (and with all others) is how to extend it to other containers (e.g. Mike mentioned Sets the other day). Apart from ugly, verbose & massively breaking changes, there is maybe one way which would be just ugly, namely putting an optional symbol just after the opening bracket, e.g. |
i.e. using square brackets infers type, using curly brackets uses type Any. Examples: {1=>2,3=>4} is a Dict{Any,Any} [1=>2,3=>4] is a Dict{Int,Int}
Examples: [ i/2 => 2i for i = 1:4 ] { i/2 => 2i for i = 1:4 }
Examples: (Int=>Int)[] (Real=>Integer)[2.0=>1,1=>0x2] (Real=>Integer)[i/2=>2i for i = 1:4]
Ok I removed the |
Yes, To extend this further, we might need to add new kinds of brackets, such as |
It's worth noting that ordinary calling syntax such as |
Add Dict comprehensions and typed Dicts -- alternative version (changes Dict literal notation)
This is an alternative version of my other pull request #1467, and it follows Stefan's proposal.
Under this framework, the rules for literal notations are more straightforward:
{...}
will use theAny
type[...]
will try to infer the type[...]
notation can be type-annontated to control the type explicitly=>
symbol anywhere, it's a Dict, otherwise it's an ArrayT[...]
, for Dicts is(K=>V)[...]
[removed the following] Additionally, there is syntax for the empty Dict case:
{=>}
. The syntax[=>]
is supported and gives aDict(None,None)
just like[]
is aVector{None}
. The syntax(K=>V)[=>]
is also supported for consistency, but it's equivalent to(K=>V)[]
. [up to here]There is no special literal syntax for the empty
Dict{Any,Any}
case; one would use either plain oldDict()
or(Any=>Any)[]
.Apart from this, everything else works like in #1467.
Notes:
{1=>2,3=>4}
is no longer aDict{Int,Int}
after this change.[...]
for Arrays and{...}
for Dicts (as said above, it's the=>
symbol which distinguishes them).Personally, I strongly prefer this framework to the previous one.