Colon / Ranges

I solved something about colon.

1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9

If upper line shows characters of string (elements of array etc.), and lower line shows the empty space / separator between two characters, then there can be two numbers i+1 and j, where i is the left and j is the right separator between characters.

Then, if “Test”[0+1:1] is “T”, “Test”[0+1:0] is separator before “T” and “Test”[1+1:1] is the separator between “T” and “e”. Then, “Test”[9+1:0] is the separator between last and first element, where it goes round in a circle.

Nope, it is an empty range.

julia> 9+1:0

(I am not sure what the question is, but it does not look like something that belogs in Internals/design, so I moved it. Also, please quote your code.)

Initially it looked like Internals / Design is the suggestion forum, and Usage is the forum about questions.

1 Like

Mathematically, the question is:

Range 0:1 is the first character, Range 5:10 is characters from 6th to 10th. But then, it’s illogical that 5 means 6th element - then, if I want to follow a conventions of Julia, I have to add one to this first element.

I don’t know where you get that from, but it is not correct.

Julia uses one-based indexing by default. 0:1 will error with that, and 5:10 will just give you elements with indexes between 5 and 10 (inclusive):

julia> az = 'a':'z'

julia> az[0:1]
ERROR: BoundsError: attempt to access 26-element StepRange{Char,Int64} at index [0:1]
 [1] throw_boundserror(::StepRange{Char,Int64}, ::Tuple{UnitRange{Int64}}) at ./abstractarray.jl:541
 [2] checkbounds at ./abstractarray.jl:506 [inlined]
 [3] getindex(::StepRange{Char,Int64}, ::UnitRange{Int64}) at ./range.jl:718
 [4] top-level scope at REPL[13]:1

julia> az[5:10]

Again, please kindly to take some time to

  1. read the relevant parts of the manual,
  2. formulate an MWE that illustrates your question,
  3. and perhaps ask an actual question if you have one.

Then it’s certainly a relief that it doesn’t :sweat_smile:


Still, it was a suggestion.

I watched a sentence “I solved something about colon” for a while. I think you missed about my word “To Solve” - for me, to have a mathematical solution. “To Learn” - to have something from the manual.

Maybe I have the use of words of mathematician, you have the ones of logician. I solved something about colon, it means, I worked with it’s mathematical rule, I did not analyze the cases of it’s logic.

I think to solve a mathematical rule means, to solve something about this syntax, not the cases it has.

To solve the cases it has, it is rather logical, I think it really has the cases you described.

julia> 22im < 23im
ERROR: MethodError: no method matching isless.

Do you see it sees it is not mathematically provable, which one is less, given this operator means mathematical is less operator, or do you see no method is implemented for this operator?

Do you want to implement is less operator on your own, or do you want to go on with mathematics of this operator?

In manual, do you see mathematics is written there, or the disassembled bytecode?

Are you happy if your code works as if it works or if it follows the meanings as defined?

Maybe I would say combine where you say solve?Or, what is the difference between HTML 2.0 <i> and <cite> tags