Skip to content
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

VIP: Change Mapping Syntax (again) #1969

Closed
fubuloubu opened this issue May 13, 2020 · 2 comments · Fixed by #2045
Closed

VIP: Change Mapping Syntax (again) #1969

fubuloubu opened this issue May 13, 2020 · 2 comments · Fixed by #2045
Labels
VIP: Approved VIP Approved

Comments

@fubuloubu
Copy link
Member

Simple Summary

Change mapping syntax from var: map(key_type, val_type) to var: HashMap[key_type, val_type]

Motivation

Mapping syntax was changed in #564. While it made for easier understanding of how mappings work in practice, it precludes the use of the Python standard function map(fn, iter) -> iter for anything in Vyper to use. We propose adopting a MyPy-like type structure, which will make working with mappings (and nested mappings) more apparent, and open up the keyword map to future use as an iterator operation.

Specification

The syntax for mappings would change from var: map(key_type, val_type) to var: HashMap[key_type, val_type]. This looks like the following in practice:

struct MyStruct: ...

my_mapping: HashMap[uint256, MyStruct]

my_nested_map: HashMap[bytes32, HashMap[uint256, address]]

@public
def foo():
    self.my_mapping[1] = MyStruct({...})  # Same access as before
    self.my_nested_map[blk.hash][1] = msg.sender  # Same access as before

Backwards Compatibility

This VIP will break the current syntax for defining mappings

Dependencies

Depends on #564

References

No references

Copyright

Copyright and related rights waived via CC0

@fubuloubu fubuloubu added the VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting label May 13, 2020
@fubuloubu fubuloubu mentioned this issue May 13, 2020
5 tasks
@iamdefinitelyahuman iamdefinitelyahuman added VIP: Approved VIP Approved and removed VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting labels May 26, 2020
@fubuloubu fubuloubu added this to the v0.2 Release milestone Jun 22, 2020
@howardpen9
Copy link

image

@howardpen9
Copy link

ok, then I know the reason why the code on this Sep 2019's paper couldn't work...

Thanks for the updated.

@fubuloubu fubuloubu removed their assignment Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VIP: Approved VIP Approved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants