VIP: 564
Title: Change Mapping Syntax
Author: @fubuloubu @grosu
Type: Standard
Status: Draft
Created: 2017-12-08
Requires: #563
Mapping syntax looks very similar to the array syntax, so we should change the syntax so it is not confusing
See above
Change Mapping Syntax to
my_mapping: map(basetype1, type2)
Nested map Syntax to look as follows:
my_mapping: map(basetype1, map(basetype1, basetype2))
Not Backwards compatible
Copyright and related rights waived via CC0
EDIT: Previous proposed syntax was my_mapping: basetype1 -> type2
@fubuloubu Could you add an example of how nested mappings would look
(maybe my_mapping: basetype1 -> (basetype2 -> basetype3?)).
my_mapping basetype1 -> basetype2 -> type3 I think that's pretty clear actually.
The harder part is how to represent the access e.g. my_mapping[acces1][access2] is how we do it now, but [ ] is the array syntax, I think we need to change it to something else.
There's also something like this in Haskell (I believe): my_mapping: (basetype1, basetype2) -> type3
Because this is how it works under the hood right? It hashes the two types together to obtain the location, right?
Meeting Notes:
Syntax would be more explicit like this
my_mapping1: map(basetype1 -> type2)
my_mapping2: map(basetype1 -> basetype2 -> type3)
my_mapping3: map(bytes <= 20 -> type2)
I like the syntax proposed by @jacqueswww :
a: public(map({int128: {bytes32: int128}}) in case of a nested map.
I sorta like it, although the syntax of structures using braces is also fairly close. Only difference is that only types can be used. Seems confusing.
I'm actually a fan of the syntax now. It's one of the things that I genuinely think is an improvement over most major languages. It's short, simple, and intuitive once you do it once or twice.
It could be interesting to use something else to enclose it perhaps. Maybe a declaration along the lines of my_mapping: basetype1<basetype2> which would make it instantly distinguishable from a list, but would keep the syntax similar. To access, you could do something like my_mapping<access> which parallels the declaration as well. It could also be a cool distinguishing feature of the language, and if < and > are used it could become know as _Vyper Fangs_.
@jacqueswww I think we need to discuss this one on our next call. Lots of options here.
This proposal was updated per discussion in #1076
I'm a fan of the new proposed my_mapping: map(basetype1, type2)
Starting on this.
@jacqueswww maybe we should _deprecate_ the old syntax with a warning to move to the new one so people know to switch?
Most helpful comment
Starting on this.