vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.84k stars 788 forks source link

VIP: support pythonic slicing #2701

Open charles-cooper opened 2 years ago

charles-cooper commented 2 years ago

Simple Summary

Allow xs[start:end] instead of slice(xs, start, len)

Motivation

It's more pythonic, less friction for new users.

Backwards Compatibility

We might want to deprecate slice.

Copyright

Copyright and related rights waived via CC0

fubuloubu commented 2 years ago
  1. would xs[start:end:step] also work?
  2. What are the restrictions on start, end and step in terms of their value? (constants, immutables, vars, etc.)
charles-cooper commented 2 years ago

I think we should disallow step for now

charles-cooper commented 2 years ago

the start and end args could have basically the same restrictions as slice, but maybe also allow negative end (so xs[start:-1] would be equivalent to slice(xs, start, len(xs) - start - 1)

tfire commented 2 years ago

👋 . Good first issue.