Vyper: VIP: Change Mapping Syntax

Created on 8 Dec 2017  路  11Comments  路  Source: vyperlang/vyper

Preamble

VIP: 564
Title: Change Mapping Syntax
Author: @fubuloubu @grosu
Type: Standard
Status: Draft
Created: 2017-12-08
Requires: #563

Abstract

Mapping syntax looks very similar to the array syntax, so we should change the syntax so it is not confusing

Motivation

See above

Specification

Change Mapping Syntax to
my_mapping: map(basetype1, type2)

Nested map Syntax to look as follows:
my_mapping: map(basetype1, map(basetype1, basetype2))

Backwards Compatibility

Not Backwards compatible

Copyright

Copyright and related rights waived via CC0


EDIT: Previous proposed syntax was my_mapping: basetype1 -> type2

Approved Discussion

Most helpful comment

Starting on this.

All 11 comments

@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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nrryuya picture nrryuya  路  4Comments

robinsierra picture robinsierra  路  3Comments

travs picture travs  路  3Comments

fubuloubu picture fubuloubu  路  3Comments

ben-kaufman picture ben-kaufman  路  4Comments