-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add a Python-like slice operator for lists and strings #983
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
Comments
Removed Type-Defect label. |
This comment was originally written by @jinmingjian great. more my idea is to enhance the slicing operator to an general indexing technology for array like objects, like:
|
This comment was originally written by [email protected] I would argue that it is not easier to read. substring says what it is doing in English, whereas string[3:2] is symbolism. |
This comment was originally written by @jinmingjian yes or no. Yes, because this is just a syntax magic. No, ":" for slicing is the tradition of numerical computing software[1]. My suggestion is more mathematical. That is, it does not pursue symbolism, it pursues intuition. The ":" is used for generating a vectorized index(i.e.,1D array). And,
So, |
This comment was originally written by @jinmingjian numerical computing software -> numerical computing language, more exactly. |
This comment was originally written by @seaneagan I think this would require a user-definable operator: List#getRange becomes: String#substring becomes: And it would probably make sense to support slicing then as well, by replacing List#setRange with: List<T> operator [:]= (List other, [int first, int last]); List#removeRange also becomes unnecessary, instead of: list.removeRange(0, 5); just do: list[:5] = []; |
Reassigning to language. This requires new syntax and is thus not a library bug. Removed Area-Library label. |
Issue #8977 has been merged into this issue. |
Please support negative indexes (relative from the end) as Python does. |
Set owner to @gbracha. |
It has been 8.5 years. substring method should accept negative values. |
Yeah, this is really weird since even Javascript String.prototype.slice() takes negative values. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice |
Any news on this? Is it ever going to happen? Doesn't sound too difficult. Is it? |
2021-01-24 [email protected] Issue #983: Static warning checks corrected. 2021-01-22 [email protected] Issue #983: triple-shift folders re-named correctly, typo in the library paths updated for 2 tests. 2021-01-21 [email protected] Fixes #985. LateInitializationError removed 2021-01-20 [email protected] Fixes #982. Add tests for The future value type of an asynchronous non-generator function part of NNBD spec 2021-01-19 [email protected] Issue #462: NNBD type-normalization tests for weak mode added. 2021-01-19 [email protected] Issue #462: NNBD type-aliases tests for weak mode added. 2021-01-19 [email protected] Issue #462: NNBD tripple-shift tests for weak mode added. 2021-01-19 [email protected] Issue #462: NNBD tests for weak mode added for the override checkings. 2021-01-19 [email protected] Issue #462: NNBD tests for weak mode added (Leatest-greatest-closures). 2021-01-19 [email protected] Issue #462: NNBD tests for weak mode added (Leatest-greatest-closures). 2021-01-18 [email protected] Fixes #981. Add tests for Return statements part of NNBD spec 2021-01-18 [email protected] Issue #462: NNBD tests for weak mode corrected according to the current Spec changes. 2021-01-14 [email protected] Issue #462: Additional comments regarding the constant evaluation issues added to weak mode tests. 2021-01-14 [email protected] Fixes #980. Remove warnings expectations for overriding default values of optional parameters tests 2021-01-13 [email protected] Issue #462: Tests for weak mode added to nnbd/weak/flow-analysis directory. 2021-01-12 [email protected] #978. Weak mode test changes 2021-01-12 [email protected] Issue #462: Tests for weak mode added to nnbd/weak directory. 2021-01-11 [email protected] Fixes #978. Tests updated according to the "flow analysis boolean variable" feature 2020-12-25 [email protected] Issues #463: Tests for weak mode added. 2020-12-25 [email protected] Issues #462, #463: Moved or added new nnbd tests for weak mode, added new tests for strong mode. 2020-12-24 [email protected] #970. Usr correct values for ProcessSignal.sigusr1 and ProcessSignal.sigusr2 on Mac 2020-12-24 [email protected] Issue #462: 1. Added nnbd tests for weak mode: exports_*, expression_typing_*, extension_method_resolution_*, future_flattening_*. 2. Moved and re-factored nnbd extension_method_resolution_*, future_flattening_* tests for weak mode into weak folder. 3. Copyrights updated Issue #463: Two exports* tests for strong mode added. 2020-12-24 [email protected] Fixes #496. Change tested date to 1 second instead of 1 day to reduce probability to change timezone on DST 2020-12-23 [email protected] Fixes #473. Remove UtilsHtml directory 2020-12-23 [email protected] Fix for Issue #462: 1. Added nnbd tests for weak mode: assignability_*, const_evaluation_*, const_objects_*, const_type_var_elimination_*. 2. Moved and re-factored nnbd exports_* tests for weak mode into weak folder. 2020-12-10 [email protected] Fixes #976. Remove obsolete errors expectations 2020-12-10 [email protected] Fixes #975. Fix wrong expected compile time error type 2020-12-07 [email protected] Flag Requirements=nnbd-weak added to the tests that run legacy code Cq-Include-Trybots: dart/try:analyzer-nnbd-linux-release-try,dart2js-nnbd-linux-x64-chrome-try,ddc-nnbd-linux-release-chrome-try,front-end-nnbd-linux-release-x64-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-x64-try,vm-kernel-nnbd-mac-release-x64-try,vm-kernel-nnbd-win-release-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try Change-Id: I69acc5c0a28fd2e7a2d38f6c9062e5a5854bdfa6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180823 Reviewed-by: William Hesse <[email protected]>
Any update? Will it be added to the language? |
By default the answer to this sort of question is: there is no update and there are no immediate plans to add it to the language. If there was any sort of update it would be posted here. Language features which are being worked on are part of the language funnel. |
@mraleph Thanks. Then maybe this issue could be closed. |
String.substring() and List.getRange() are somewhat verbose, but very common operations. Python's slice operator provides an easy-to-read notation to replace these.
Examples of substring() and slice [:]
string.substring(a) -> string[a:]
string.substring(a, b) -> string[a:b]
string.substring(0, a) -> string[:a]
The text was updated successfully, but these errors were encountered: