Soumya
Soumya

Reputation: 95

What does double dot (..) in Julia Programming Language mean?

For example in the code below, x is defining the domain, but why is there the double dot between 0 and 4pi?

using ApproxFun
x=Fun(identity,0..4π)

Upvotes: 5

Views: 1113

Answers (2)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42194

.. is not part of Julia, rather part of the packages used by ApproxFun.

It is used to represent intervals, see the code below

julia> u = 1..3
1..3

julia> dump(u)
Interval{:closed,:closed,Int64}
  left: Int64 1
  right: Int64 3

So this is just a convenience constructor for the Interval object, see:

julia> 1..3 === Interval{:closed,:closed,Int64}(1,3)
true

Upvotes: 3

fredrikekre
fredrikekre

Reputation: 10984

.. is an operator (like e.g. +) but it does not have a default definition. You can define it to to whatever you want:

julia> ..(a, b) = println(a, ", ", b)
.. (generic function with 1 method)

julia> "hello" .. "world"
hello, world

The Julia package IntervalArithmetic uses it to construct an interval, e.g.

julia> using IntervalArithmetic

julia> 4..5
[4, 5]

julia> typeof(4..5)
Interval{Float64}

and I suspect this is what it is used for in your code example.

Upvotes: 10

Related Questions