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

Add python like Sliceable[start:end] operator to vyper #4345

Open
Philogy opened this issue Nov 2, 2024 · 3 comments
Open

Add python like Sliceable[start:end] operator to vyper #4345

Philogy opened this issue Nov 2, 2024 · 3 comments
Labels
VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting

Comments

@Philogy
Copy link

Philogy commented Nov 2, 2024

Simple Summary

Instead of typing out slice(my_sliceable_var, start, length) I'd like to be able to use slice syntax i.e. my_sliceable_var[start:end]. It should have the same behavior and be bounds-checked.

An alternative would be to implement Rust's slicing syntax [start..end] and [start..=end]. What's nice about Rust's approach is that gives syntatic sugar to differentiate between exclusive and inclusive ranges which can be nice. Reused it could serve as syntax sugar for range in the future.

Motivation

The slice builtin leads to some relatively verbose syntax. Square brackets are widely recognized across several languages to represent slicing and will be familiar to most people. Both Solidity & Python support the slicing operator in the form of [start:end]. Rust is quite popular too so [start..end] will be familiar to a lot of devs too.

Specification

TBD.

Backwards Compatibility

Backwards compatible as this wasn't valid syntax before.

Dependencies

None afaik.

References

Copyright

Copyright and related rights waived via CC0

@Philogy Philogy added the needs triage needs triage label Nov 2, 2024
@charles-cooper charles-cooper added VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting and removed needs triage needs triage labels Nov 4, 2024
@charles-cooper
Copy link
Member

charles-cooper commented Nov 4, 2024

i've been thinking about this for awhile and it would be good to replace the slice builtin. the nice thing is it gives us a way to fix the current API ugliness of slice() (iirc, it is very frustrating that it reverts when the requested length is larger than the length of the provided bytestring, this usually comes up during bytestring building routines)

@charles-cooper
Copy link
Member

ah, dup of #3562 (but i left the specification as a stub)

@charles-cooper
Copy link
Member

related: #3560

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting
Projects
None yet
Development

No branches or pull requests

2 participants