Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^6: Converting python list range expressions to perl

by LanX (Saint)
on Dec 05, 2022 at 14:23 UTC ( [id://11148566]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Converting python list range expressions to perl
in thread Converting python list range expressions to perl

> OFFSET:LENGTH vs. OFFSET:OFFSET may be purely semantics.

doesn't seem so.

https://docs.python.org/3/glossary.html#term-slice

slice An object usually containing a portion of a sequence. A slice is creat +ed using the subscript notation, [] with colons between numbers when several are given, such as in variable_nam +e[1:3:5]. The bracket (subscript) notation uses slice objects internally.

https://docs.python.org/3/library/functions.html#slice

class slice(stop) class slice(start, stop, step=1) Return a slice object representing the set of indices specified by ran +ge(start, stop, step). The start and step arguments default to None. ...

something is off (-set ;) with this test suite. Unfortunately I have no Python at hand to test ...

updates

references and citations updated

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^7: Converting python list range expressions to perl
by kcott (Archbishop) on Dec 05, 2022 at 19:02 UTC

    In the OP, a notation that looked like [x:y], where x or y could be blank, was given. I noted this equivalence:

    PythonPerl
    [x:y]splice ARRAY, x, y
    [:y]splice ARRAY, 0, y
    [x:]splice ARRAY, x
    [:]splice ARRAY, 0

    I coded that and it passed all tests. I took all given tests, and their results, on face value. One exception is [:], which I added myself and was extrapolated from information already provided.

    If the original data was wrong in some way, then I'm working from a false premise. If the tests are insufficient, further tests could show that the seen equivalence doesn't hold for other values.

    I'm not trying to sell something here. I don't care what the OP uses for his "poetry" project — as already stated: "What you choose is entirely up to you.".

    If you think that there's something wrong with the source, please take it up with the OP, not me.

    — Ken

      > please take it up with the OP, not me.

      I'm not "taking it up with you".

      This is a public thread, other readers may get interested to dig deeper.

      edit

      I was just writing up my findings literally "for the record", before they get lost.

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

        You've removed the leading "If you think that there's something wrong with the source, ", thereby changing the context.

        If you think that there's something wrong with what I've written, by all means take it up with me.

        If you think that there's something wrong with the source, take it up with the OP.

        — Ken

        A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148566]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found