# Think Julia exercise 7-3

**URL:** https://discourse.julialang.org/t/think-julia-exercise-7-3/26682
**Category:** New to Julia
**Tags:** question
**Created:** [July 23, 2019, 12:53pm UTC](https://discourse.julialang.org/t/think-julia-exercise-7-3/26682 "2019-07-23T12:53:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Dito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dito/32/10039_2.png) [@Dito](https://discourse.julialang.org/u/Dito)
#### Post date: [July 23, 2019, 12:53pm UTC](https://discourse.julialang.org/t/think-julia-exercise-7-3/26682/1 "2019-07-23T12:53:11Z")

</div>

The built-in function Meta.parse takes a string and transforms it into an expression. This expression can be evaluated in Julia with the function Core.eval. For example:

```nohighlight
julia> expr = Meta.parse("1+2*3")
:(1 + 2 * 3)
julia> eval(expr)
7
julia> expr = Meta.parse("sqrt(π)")
:(sqrt(π))
julia> eval(expr)
1.7724538509055159

```

Write a function called evalloop that iteratively prompts the user, takes the resulting input and evaluates it using eval, and prints the result. It should continue until the user enters done, and then return the value of the last expression it evaluated.

I only did this

```nohighlight
function Evaloop()

    while true
        print("input: ")
        a=Meta.parse(readline())
        if typeof(a)==Symbol 
            break
        elseif a.head==:call
            println(eval(a))
        elseif error("input must be expression")
        end 
    end
end
Evaloop()

```

I couldn’t write code that stops by entering Done

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [July 23, 2019, 1:32pm UTC](https://discourse.julialang.org/t/think-julia-exercise-7-3/26682/2 "2019-07-23T13:32:03Z")

</div>

How about:

```julia
julia> function evaloop()
           while true
               print("input: ")
               l = readline()
               if l=="done"
                   break
               end
               try
                   println(eval(Meta.parse(l)))
               catch e
                   println(e)
               end
           end
       end

```
