# String Colon String Would Fit The Language

**URL:** <https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090>\
**Category:** Community\
**Tags:** languageserver\
**Created:** [October 10, 2020, 7:12am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090 "2020-10-10T07:12:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaeli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaeli/32/19877_2.png) [@vaeli](https://discourse.julialang.org/u/vaeli)\
**Post date:** [October 10, 2020, 7:12am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/1 "2020-10-10T07:12:31Z")

</div>

How is called the colon operator?

Logically, using colons for strings as an abstract operation would fit the language. It is clear for ordered lists, like “a”, “b”, “c”, “d” gives “b”:“c” value “b”, “c”; where ordered alphabet leaves open the exact elements of a list, but for any ordered list it is known. If ranges and elements are separated, the list meaning would be known for any array type, but where range=elements, meaning for this list for a subset dimension would be known for any dictionary.

There are many cases where order of list matters, in case of strings - most simple on the operational level would be dictionary pages, where values also have to be cut in the middle, with layout and size of the string, so that strings are combined with numbers; I don’t know whether it is “string”:12:“String”:13; or “string”:“String”, 12:13 or [“string”::n12]:[“String”::n13] (view [Review of the Collins COBUILD Advanced Learner’s English Dictionary | Antimoon](http://www.antimoon.com/how/cobuild-review.htm)). Layouts, which could return such data about their elements, should be supported.

I wasn’t very serious about all of that, but it shows that having simply an object, which contains two strings and a colon between them, and knows it’s simpler use cases, where you give it to the ordered strings container or container of written numbers (maybe including simple syntax for mathematical formulas, even in abstract space), could lead many common cases to much more clarification.

 ![](https://global.discourse-cdn.com/julialang/original/3X/6/2/623b491892336abd8157a3cff728297b9b7b2bc5.jpeg)

It is also interesting question, how to order dictionary, which has german and estonian letters mixed? Is it the same “Ü” in German alphabet and the “Ü” in Estonian alphabet or is it not? Is this the same word if German and Spanish words have exactly the same letters?

Allowing also multidimensional string dictionaries would not break it. Say, I take a Chemical elements table and express the components I can make with GChemCalc syntax. This will give me a whole infinity of mathematical expressions, but it also matter, which ones I plan to ever use - so I can leave the syntax wholly abstract.

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [October 10, 2020, 7:49am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/2 "2020-10-10T07:49:53Z")

</div>

You can overload `(::Colon)(x, y)` if you want to. Here is how you can define `string1:string2` to be an object “holding” all strings that are lexicographically between `string1` and `string2`.

```julia
struct StrRange
	first::String
	last::String
end

(::Colon)(s1::AbstractString, s2::AbstractString) = StrRange(extrema((s1, s2))...)

Base.in(s::AbstractString, sr::StrRange) = sr.first <= s <= sr.last

"hello" in "abracadabra":"zebra" # true

```

---

<div class="post-metadata">

**Author:** ![vaeli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaeli/32/19877_2.png) [@vaeli](https://discourse.julialang.org/u/vaeli)\
**Post date:** [October 10, 2020, 8:49am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/3 "2020-10-10T08:49:31Z")

</div>

Yes this is a philosophical question, something about Citizenship of programming models. You make it first class Cityzen, but

does it matter if it is a large object, or a small element working bloody fast and often removed more or less by a compiler, leaving only a small rudiment? If it is a mathematical object worth several million computations, or is it worth less than one computation (objects, which are removed by compiler in many cases, looking only that they structurally fit there, objects, which are only left there by a compiler sometimes and asserted other times, that they syntactically fit there).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 11, 2020, 9:37am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/4 "2020-10-11T09:37:46Z")

</div>

> [@vaeli](#):
>
> this is a philosophical question

I am not sure about this — I think it is a practical one. `AbstractUnitRange` and its subtypes were introduced to provide a compact representation for _vectors_ that have a very regular structure, but in practice these are really just vectors.

In contrast, I don’t think that you want to treat eg `"abracadabra":"zebra"` as an `<:AbstractVector`, since it has infinitely many elements. If you find @Vasily_Pisarev’s `StrRange` implementation above useful, just use it in your own code, but note that providing a method for `:` is type piracy, so I would suggest a different constructor.

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [October 11, 2020, 9:59am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/5 "2020-10-11T09:59:09Z")

</div>

Rather than ranges, perhaps a better analogy is to intervals, which have endpoints & membership but aren’t thought of as having an integer length. It looks like this just works:

```julia
julia> using IntervalSets

julia> 1.5 in 0..pi
true

julia> "hello" in "abracadabra".."zebra"
true

```

---

<div class="post-metadata">

**Author:** ![vaeli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaeli/32/19877_2.png) [@vaeli](https://discourse.julialang.org/u/vaeli)\
**Post date:** [October 11, 2020, 10:37am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/6 "2020-10-11T10:37:31Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![vaeli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaeli/32/19877_2.png) [@vaeli](https://discourse.julialang.org/u/vaeli)\
**Post date:** [October 11, 2020, 10:41am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/7 "2020-10-11T10:41:14Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![vaeli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaeli/32/19877_2.png) [@vaeli](https://discourse.julialang.org/u/vaeli)\
**Post date:** [October 11, 2020, 11:10am UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/8 "2020-10-11T11:10:10Z")

</div>

(For the other parts, I will reply later - I definitely agree about the type privacy, this was my first thought that this kind of operator must be described in syntactic level, such that it would act like a nothing, the example override I would rather solve with long functions, which give some hint that there is something going on behind this). Rather than using override, I would describe with comments, what the variables are, and give some math - this is basically what a primitive is doing, that it knows it’s math; I mean pi is a pi and you can know that if you resize your screen to million five thousand times five thousand, you will need to check whether your pi works with programs - even worse if it happens late in the history; definitely, in the beginning of history, pi just meant 3.14.

---

<div class="post-metadata">

**Author:** ![vaeli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaeli/32/19877_2.png) [@vaeli](https://discourse.julialang.org/u/vaeli)\
**Post date:** [October 11, 2020, 8:56pm UTC](https://discourse.julialang.org/t/string-colon-string-would-fit-the-language/48090/9 "2020-10-11T20:56:29Z")

</div>

Well this is still assuming that string literals are infinite; for reality this is very often not the case; as an analogue, even the numbers for 0…pi form an infinite set.

For my free time, I have done thousands of little programs, which know, what is a “syllable”.

And thank anyway for discussion exists - I just solved, what to do with my complex number [Colons] / dimensions, so I think this one can also not be unfruitful.
