GithubHelp home page GithubHelp logo

Comments (12)

cburgmer avatar cburgmer commented on June 3, 2024 2

There is no consensus for ["first", "second", "third", "fourth", "fifth"][3::-1] so far, but certainly a "productive" majority (as in non-empty responses) for the Python way: https://cburgmer.github.io/json-path-comparison/results/array_slice_with_open_end_and_negative_step.html

from json-path-comparison.

cburgmer avatar cburgmer commented on June 3, 2024 2

For me the best argument so far was "follow what Python is doing". For many developers that would probably be the least surprise. If we have another widely adopted implementation out there then let's put it on the table.

from json-path-comparison.

glyn avatar glyn commented on June 3, 2024 1

Unfortunately, those old 2.0 docs are silent about what happens when stride < 0. Experimentally, Python 3 seems to adopt the "forwards A" interpretation:

$ python3
>>> ["first", "second", "third", "fourth", "fifth"][3:0:-1]
['fourth', 'third', 'second']
>>> ["first", "second", "third", "fourth", "fifth"][3:-1:-1]
[]
>>> ["first", "second", "third", "fourth", "fifth"][3::-1]
['fourth', 'third', 'second', 'first']
>>> ["first", "second", "third", "fourth", "fifth"][:0:-1]
['fifth', 'fourth', 'third', 'second']

from json-path-comparison.

glyn avatar glyn commented on June 3, 2024 1

I'm not aware of other open questions, so I think it's ok to change the implementation. As a cross-check, if you bump yaml-jsonpath, its behaviour should agree with what's needed here.

from json-path-comparison.

cleidiano avatar cleidiano commented on June 3, 2024 1

Got it, currently my implementation does not support negative step, there is a open issue to implement it, but I will freeze and wait a little bit.

from json-path-comparison.

cburgmer avatar cburgmer commented on June 3, 2024

Thanks for the thorough analysis.

I added another comparison Array slice with negative step and start greater than end.

I believe at the time of creating the query no implementation was returning anything meaningful for that, so I did not include it.

One more datapoint (and something users would compare to?):

$ python3
>>> ["first", "second", "third", "forth", "fifth"][0:3:-2]
[]
>>> ["first", "second", "third", "forth", "fifth"][3:0:-2]
['forth', 'second']

from json-path-comparison.

remorhaz avatar remorhaz commented on June 3, 2024

As for me, I've just used python (which seems to be used as a basis for ES4 slice proposal) spec/CLI to verify if my implementation works the same.

from json-path-comparison.

remorhaz avatar remorhaz commented on June 3, 2024

Old 2.0 docs seem to contain a bit more info.

from json-path-comparison.

cburgmer avatar cburgmer commented on June 3, 2024

I think at this stage I would try to follow the Python implementation, minus throwing an error if nothing was found, because that's up to the underlying implementation to decide.

If we agree, are there any open questions, or do we just need to make the change in the implementation?

from json-path-comparison.

cleidiano avatar cleidiano commented on June 3, 2024

Sorry for the late interaction, but Backwards seems to have advantages:

  • All rules that it's applied when step is positive and already have a consensus could be applied.
  • The only thing the user need to know is the direction that the operation would occur.

from json-path-comparison.

glyn avatar glyn commented on June 3, 2024

@cleidiano I initially adopted the Backwards approach in my implementation because of the advantages you describe. But I changed my mind becauset the Backwards behaviour is probably unintuitive to programmers familiar with for loops. I switched to Forwards A.

from json-path-comparison.

cburgmer avatar cburgmer commented on June 3, 2024

Closing this, at it seems we are happy with the way Proposal A is implementing this.

from json-path-comparison.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.