[GO] About the case that ("b" .. "aa") could not be used in Ruby Range

background

The beginning of the matter

  1. Kinx supports the range of strings like Ruby, but since "a" is next to "z", it's simply I defined a <=> operator that is not in lexicographical order. If you sort normally in 2., it will not be in lexicographic order, of course. (Because it is judged that the longer the character string is, the larger it is)
  2. By the way, Ruby is in lexicographical order, sorting strings. ** Something strange **.

[Note] What is Kinx? First motive ⇒ Please see here Repository ⇒ Please see here

I checked

  1. Let's try " b "<=>" aa " with irb,

    irb(main):001:0> "b" <=> "aa"
    => 1
    irb(main):002:0>
    
  2. ** What? !! ** **

  3. So what about Range? When I try to display " a ".." c ".

    irb(main):002:0> a = "a".."c"
    => "a".."c"
    irb(main):003:0> a.each {|e| p e }
    "a"
    "b"
    "c"
    => "a".."c"
    
  4. It will be listed properly. So what about the alleged " b ".." aa "?

    irb(main):004:0> a = "b".."aa"
    => "b".."aa"
    irb(main):005:0> a.each {|e| p e }
    => "b".."aa"
    
  5. Why can't I use " b ".." aa " ...

Conclusion

My feeling

After all, " b ".." aa " also ** wants you to move **, isn't it? After " b " is"c", I wanted you to continue to"z"and then end with"aa", but what about other people?

What I actually did

So, in Latest repository (not included in 0.8.1), I modified it as follows.

  1. The <=> operator of the string is returned in lexicographic order.
  2. The <=> part of class Range is treated specially only for character strings so that"b" .. "aa"can also be used.

in conclusion

So, here (= Specification of Range for characters) is different from Ruby. Please let us know if you have any problems.

Well, I don't use it much under such special conditions, so no one seems to be in trouble. So if you say which one is fine, it may be either one. It was a detailed story.

How about Ruby? Is it within expectations or unexpected? Is it intentional or not? Well, the definition is clear and the operation follows the definition, so it seems calm with this kind of thing = specification.

See you next time.

Recommended Posts

About the case that ("b" .. "aa") could not be used in Ruby Range
The case that @Autowired could not be used in JUnit5
The story that the Servlet could not be loaded in the Java Web application
The case that "apt-get update" defined in "Dockerfile" could not be done at the time of "docker-compose build"
About the matter that hidden_field can be used insanely
The story that the forced update could not be implemented
Ruby on Rails 5 quick learning practice guide that can be used in the field Summary
About the range and scope where Day16 variables can be used
Correspond to "error that basic authentication does not pass" in the test code "The story that could not be done"
About the problem that the server can not be started with rails s
[Rails] About the error that the image is not displayed in the production environment
[CentOS8] Since the javac command could not be used, install the java development environment.
I didn't know that inner classes could be defined in the [Java] interface
[Ruby] Methods that can be used with strings
About regular expressions used in ruby sub method
The story that the port can no longer be used in the Spring boot sample program
Solved the problem that the test could not be executed from the command line with spring-boot-starter-test
The story that the variable initialization method called in the Java constructor should not be overridden
About the difference between classes and instances in Ruby
Range where variables can be used with ruby [Scope]
Convenient shortcut keys that can be used in Eclipse
The story that the request parameter from the iPhone application could not be obtained successfully with the Servlet
Solved the problem that apt-get update could not be executed on Ubuntu (Virtual Box) on Windows.
Learning Ruby with AtCoder Beginners Selection [Some Sums] Increase the methods that can be used
About eval in Ruby
About the [ruby] operator
Determine that the value is a multiple of 〇 in Ruby
[Question] Can nullif be used in the count function in JPQL?
About the difference between "(double quotation)" and "single quotation" in Ruby
Introduction to Rakefile that can be done in about 10 minutes
[Ruby] About the difference between 2 dots and 3 dots of range object.
Java 14 new features that could be used to write code
[Development log ⑬] Do not let 0 be entered in the form !!
About the matter that: nth-child (-n + m) does not work as intended in the selector of jsoup