# Unable to convert Linspace to Range in a function

**URL:** <https://discourse.julialang.org/t/unable-to-convert-linspace-to-range-in-a-function/83943>\
**Category:** General Usage\
**Created:** [July 8, 2022, 11:18am UTC](https://discourse.julialang.org/t/unable-to-convert-linspace-to-range-in-a-function/83943 "2022-07-08T11:18:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 8, 2022, 11:18am UTC](https://discourse.julialang.org/t/unable-to-convert-linspace-to-range-in-a-function/83943/1 "2022-07-08T11:18:42Z")

</div>

Hi all, I want to plot partitions of Riemann Sums from this blog:  
[https://julialang.org/blog/2017/03/piday/](https://julialang.org/blog/2017/03/piday/)

The problem is since it is from 2017 article, it is using linspace, I read around and see it is replaced by range. I try to convert it and it has problem still.  
**LoadError: UndefVarError: … not defined**  
**[1] (::var"#23#24"{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}})(i::Int64)**  
\*\* @ Main ./twiceprecision.jl:0\*\*  
…

This is the code

```julia
using Plots, LaTeXStrings
gr()

f(x) = √(4 - x^2)

#plot(f, 0, 2, aspect_ratio=:equal, fill=(0, :green), alpha=0.2, label="")

function make_intervals(N=10)
    xs = range(0, stop=2, length=11)
    return [xs[i]..xs[i+1] for i in 1:length(xs)-1]
end

intervals = make_intervals(30)

p = plot(aspect_ratio=:equal)
for X in intervals
    Y = f(X)

    plot!(IntervalBox(X, Interval(0, Y.lo)), c=:blue, label="", alpha=0.1)
    plot!(IntervalBox(X, Interval(Y.lo, Y.hi)), c=:red, label="", alpha=0.1)
end

plot!(f, 0, 2)

p

```

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [July 8, 2022, 11:53am UTC](https://discourse.julialang.org/t/unable-to-convert-linspace-to-range-in-a-function/83943/2 "2022-07-08T11:53:57Z")

</div>

It looks like you have a typo in your error message; it should be

```julia
ERROR: UndefVarError: .. not defined

```

(You have an extra `.`.)

Anyway, the error message points to the problem:

```julia
return [xs[i]..xs[i+1] for i in 1:length(xs)-1]

```

uses `..`, which is undefined. It can be defined by importing ValidatedNumerics.jl, which was imported earlier on in the blog post.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 8, 2022, 1:09pm UTC](https://discourse.julialang.org/t/unable-to-convert-linspace-to-range-in-a-function/83943/3 "2022-07-08T13:09:22Z")

</div>

> [@StevenWhitaker](#):
>
> ValidatedNumerics.jl

Yes it is a typo should be `..` not `...`

Thanks for pointing the package…

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 8, 2022, 1:39pm UTC](https://discourse.julialang.org/t/unable-to-convert-linspace-to-range-in-a-function/83943/4 "2022-07-08T13:39:39Z")

</div>

@StevenWhitaker

Why there occurs another error when I type:  
`setdisplay(:standard, sigfigs=5)`

**UndefVarError: setdisplay not defined**

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [July 8, 2022, 3:45pm UTC](https://discourse.julialang.org/t/unable-to-convert-linspace-to-range-in-a-function/83943/5 "2022-07-08T15:45:58Z")

</div>

A different package exports `setdisplay` (not sure what one, but you could look through the blog post to see what packages are imported and see what one of those defines `setdisplay`).
