# Problem with let declaration v0.6

**URL:** <https://discourse.julialang.org/t/problem-with-let-declaration-v0-6/4998>\
**Category:** General Usage\
**Tags:** question, bug\
**Created:** [July 21, 2017, 2:44pm UTC](https://discourse.julialang.org/t/problem-with-let-declaration-v0-6/4998 "2017-07-21T14:44:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [July 21, 2017, 2:44pm UTC](https://discourse.julialang.org/t/problem-with-let-declaration-v0-6/4998/1 "2017-07-21T14:44:26Z")

</div>

I am pretty sure that the following code was working in julia v0.5. It is a simple recursive walk in a tree given by a root and a function children (the array of children of its argument).

```
walk(root, children) =
   let result = Set([root]), 
       grep(r) = if (r != []) 
                     for t in children(r) ; push!(result, t) ; grep(t); end
                 end
       grep(root) 
       result
   end

move(x) = x > 10 ? [] : [x+1]

```

This returns an error, as if the recursive definition of the local function grep is not valid.

```
julia> walk(0, move)
ERROR: UndefVarError: grep not defined
Stacktrace:
 [1] walk(::Array{Int64,1}, ::#move) at ./none:1

```

Can someone confirm the error? Is there some change concerning let declarations in v0.6? If I remove the let form, everything works as expected.

```
function walk2(root, children)
    result = Set([root])
    grep(r) = if (r != []) 
                 for t in children(r) ; push!(result, t) ; grep(t) ; end
              end
    grep(root)
    result
end

julia> walk2(0, move)
Set([2, 11, 0, 7, 9, 10, 8, 6, 4, 3, 5, 1])

```

---

<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:** [July 21, 2017, 4:45pm UTC](https://discourse.julialang.org/t/problem-with-let-declaration-v0-6/4998/2 "2017-07-21T16:45:32Z")

</div>

I can’t help you with the original issue (I am not totally sure `let` accepts this function syntax), but if you write it more like Julia and less like Lisp, it works fine:

```julia
function walk(root, children)
    result = Set([root])
    function grep(r)
        if r != []
            for t in children(r)
                push!(result, t)
                grep(t)
            end
        end
    end
    grep(root) 
    result
end

move(x) = x > 10 ? [] : [x+1]

walk(0, move)

```

---

<div class="post-metadata">

**Author:** ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)\
**Post date:** [July 21, 2017, 6:00pm UTC](https://discourse.julialang.org/t/problem-with-let-declaration-v0-6/4998/3 "2017-07-21T18:00:30Z")

</div>

Like in lisp, the right-hand side of a `let` binding refers to the outer scope. But definitions within a block act like `letrec`, so if you delete the comma (moving the definition of `grep` inside the let block) it works. But there also seems to be a bug here if you try to refer to an outer function with the same name inside a let binding.
