You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "jiahuili430 (via GitHub)" <gi...@apache.org> on 2025/01/13 15:02:47 UTC
[PR] Elixir: Fix negative steps [couchdb]
jiahuili430 opened a new pull request, #5397:
URL: https://github.com/apache/couchdb/pull/5397
<!-- Thank you for your contribution!
Please file this form by replacing the Markdown comments
with your text. If a section needs no action - remove it.
Also remember, that CouchDB uses the Review-Then-Commit (RTC) model
of code collaboration. Positive feedback is represented +1 from committers
and negative is a -1. The -1 also means veto, and needs to be addressed
to proceed. Once there are no objections, the PR can be merged by a
CouchDB committer.
See: http://couchdb.apache.org/bylaws.html#decisions for more info. -->
## Overview
Related PR: https://github.com/apache/couchdb/pull/5372
Related issue: https://github.com/apache/couchdb/issues/5386
<!-- Please give a short brief for the pull request,
what problem it solves or how it makes things better. -->
## Testing recommendations
`make elixir`
<!-- Describe how we can test your changes.
Does it provide any behaviour that the end users
could notice? -->
## Related Issues or Pull Requests
<!-- If your changes affect multiple components in different
repositories please put links to those issues or pull requests here. -->
## Checklist
- [ ] Code is written and works correctly
- [ ] Changes are covered by tests
- [ ] Any new configurable parameters are documented in `rel/overlay/etc/default.ini`
- [ ] Documentation changes were made in the `src/docs` folder
- [ ] Documentation changes were backported (separated PR) to affected branches
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "jiahuili430 (via GitHub)" <gi...@apache.org>.
jiahuili430 merged PR #5397:
URL: https://github.com/apache/couchdb/pull/5397
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on code in PR #5397:
URL: https://github.com/apache/couchdb/pull/5397#discussion_r1913555601
##########
test/elixir/test/view_pagination_test.exs:
##########
@@ -59,7 +59,7 @@ defmodule ViewPaginationTest do
query_function = "function(doc) { emit(doc.integer, null); }"
- 100..0//-1
+ 100..0//1
Review Comment:
I think it's for string slicing only?
Otherwise for range we'd end up with an empty range:
```
> Enum.to_list(100..0//-1)
[100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82,
81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62,
61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, ...]
> Enum.to_list(100..0//1)
[]
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "big-r81 (via GitHub)" <gi...@apache.org>.
big-r81 commented on PR #5397:
URL: https://github.com/apache/couchdb/pull/5397#issuecomment-2587772778
I think the problem is the `-1` from
```
warning: negative steps are not supported in String.slice/2, pass 14..-1//1 instead
```
The index can't be negative in `String.slice` but it's Elixir ...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "jiahuili430 (via GitHub)" <gi...@apache.org>.
jiahuili430 commented on code in PR #5397:
URL: https://github.com/apache/couchdb/pull/5397#discussion_r1913572016
##########
test/elixir/test/view_pagination_test.exs:
##########
@@ -59,7 +59,7 @@ defmodule ViewPaginationTest do
query_function = "function(doc) { emit(doc.integer, null); }"
- 100..0//-1
+ 100..0//1
Review Comment:
Thanks for the example, updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on PR #5397:
URL: https://github.com/apache/couchdb/pull/5397#issuecomment-2587799096
> I think the problem is the `-1` from
>
> ```
> warning: negative steps are not supported in String.slice/2, pass 14..-1//1 instead
> ```
>
> The index can't be negative in `String.slice` but it's Elixir ...
ikr! it's kind of inconsistent how it works with ranges. It shouldn't even accept a range and use a specialized slicing. I like python's slicing a bit better in general.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "jiahuili430 (via GitHub)" <gi...@apache.org>.
jiahuili430 commented on code in PR #5397:
URL: https://github.com/apache/couchdb/pull/5397#discussion_r1913599934
##########
test/elixir/test/uuids_test.exs:
##########
@@ -88,7 +88,7 @@ defmodule UUIDsTest do
Enum.reduce(resp.body["uuids"], fn curr, acc ->
assert String.length(curr) == 14 + String.length(@utc_id_suffix)
- assert String.slice(curr, 14..-1//-1) == @utc_id_suffix
+ assert String.slice(curr, 14..-1//1) == @utc_id_suffix
Review Comment:
- `-14..-1` doesn't work:
```bash
$ make elixir tests=test/elixir/test/uuids_test.exs
* test utc_id uuids are correct (9.4ms) [L#85]
1) test utc_id uuids are correct (UUIDsTest)
test/elixir/test/uuids_test.exs:85
Assertion with == failed
code: assert String.slice(curr, -14..-1) == @utc_id_suffix
left: "9a44beed58frog"
right: "frog"
stacktrace:
test/elixir/test/uuids_test.exs:91: anonymous fn/2 in UUIDsTest."test utc_id uuids are correct"/1
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/2-lists^foldl/2-1-"/3
test/elixir/test/uuids_test.exs:89: (test)
```
- `14..-1` get following warnings:
```
warning: 14..-1 has a default step of -1, please write 14..-1//-1 instead
test/elixir/test/uuids_test.exs:91: UUIDsTest."test utc_id uuids are correct"/1
...
warning: negative steps are not supported in String.slice/2, pass 14..-1//1 instead
(elixir 1.18.1) lib/string.ex:2418: String.slice/2
test/elixir/test/uuids_test.exs:91: anonymous fn/2 in UUIDsTest."test utc_id uuids are correct"/1
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/2-lists^foldl/2-1-"/3
test/elixir/test/uuids_test.exs:89: UUIDsTest."test utc_id uuids are correct"/1
(ex_unit 1.18.1) lib/ex_unit/runner.ex:511: ExUnit.Runner.exec_test/2
(stdlib 6.2) timer.erl:595: :timer.tc/2
(ex_unit 1.18.1) lib/ex_unit/runner.ex:433: anonymous fn/6 in ExUnit.Runner.spawn_test_monitor/4
```
- `14..-1//1` no warnings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on code in PR #5397:
URL: https://github.com/apache/couchdb/pull/5397#discussion_r1913605208
##########
test/elixir/test/uuids_test.exs:
##########
@@ -88,7 +88,7 @@ defmodule UUIDsTest do
Enum.reduce(resp.body["uuids"], fn curr, acc ->
assert String.length(curr) == 14 + String.length(@utc_id_suffix)
- assert String.slice(curr, 14..-1//-1) == @utc_id_suffix
+ assert String.slice(curr, 14..-1//1) == @utc_id_suffix
Review Comment:
Ah you're right, I was confused by the silly syntax. Let's stick with what we have then!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Elixir: Fix negative steps [couchdb]
Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on code in PR #5397:
URL: https://github.com/apache/couchdb/pull/5397#discussion_r1913586846
##########
test/elixir/test/uuids_test.exs:
##########
@@ -88,7 +88,7 @@ defmodule UUIDsTest do
Enum.reduce(resp.body["uuids"], fn curr, acc ->
assert String.length(curr) == 14 + String.length(@utc_id_suffix)
- assert String.slice(curr, 14..-1//-1) == @utc_id_suffix
+ assert String.slice(curr, 14..-1//1) == @utc_id_suffix
Review Comment:
Would `-14..-1` work here?
To avoid the silly forced `//1` step.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org