Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: A proper name for is_sorted function that can check more than just sorting order?

by aitap (Curate)
on Dec 25, 2017 at 10:25 UTC ( [id://1206162]=note: print w/replies, xml ) Need Help??


in reply to A proper name for is_sorted function that can check more than just sorting order?

I would try to place the words all and reduce in the name of the function so the users would get the semantics by references to other well-known standard library functions.

Clearly, naming things and off-by-one errors are the three hardest things in programming.

  • Comment on Re: A proper name for is_sorted function that can check more than just sorting order?

Replies are listed 'Best First'.
Re^2: A proper name for is_sorted function that can check more than just sorting order?
by ikegami (Patriarch) on Dec 25, 2017 at 20:42 UTC

    Or you could actually use all.

    all { $res[$_ - 1]{end_date} eq $res[$_]{start_date} } 1 .. $#res

    Or if you want to know which ones are "bad" so you can output a message for each of them:

    map { $res[$_ - 1] } grep { $res[$_ - 1]{end_date} ne $res[$_]{start_date} } 1..$#res
Re^2: A proper name for is_sorted function that can check more than just sorting order?
by Anonymous Monk on Dec 25, 2017 at 18:27 UTC

    Exactly right, the problem is broken down via reduce and then some characterization. Ordering can be ascending/descending, strict/non-strict, involve numeric/string compare, etc.

    However, the example given is a test for gaps or discontinuities rather than ordering. This, and the other topic relating to Testing, makes me think the concept OP is looking for might be invariant.

      In fact the "concept OP is looking for" is called dependent type theory. However, this isn't even remotely implementable in Perl. Possibly in Scala or Haskell, definitely in more advanced languages like Idris. Not sure about Perl6.

      So in the absence of "you cannot do it in a way that breaks invariants" types, a mixture of runtime/unit tests that can be fine-tuned on accuracy<------>speed scale makes for a poor but workable substitute.

      In my opinion, anyway, but I'm going to put it to the test the hard way.

        Why not OO framework then? Getters/setters, methods all in one place with internal logic and consistency checks as required. What problem is this that cannot be abstracted and subdivided into parts?

Log In?
Username:
Password:

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

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

    No recent polls found