What does the return keyword do in a let/begin block?

Hi, I couldn’t find in the documentation an explanation to this behavior.

let
    "let block without return"
end |> println
# OUTPUT: let block without return

let
    return "let block with return"
end |> println
# OUTPUT: "let block with return"
# NOTE: the double quotes are actually printed

let
    "let block without return"
end |> typeof |> println
# OUTPUT: String

let
    return "let block with return"
end |> typeof |> println
# OUTPUT: "let block with return"
# NOTE: What is going on?

var1 = let
    "let block without return"
end
println("`var1` is assigned to: ", var1)
# OUTPUT: `var1` is assigned to: let block without return

var2 = let
    return "let block with return"
end
println("`var2` is assigned to: ", var2)
# OUTPUT: ERROR: LoadError: UndefVarError: var2 not defined[...]
# NOTE: What is going on?

A similar behaviour occurs with begin blocks.

I’m using julia 1.6.1

Thanks!

1 Like
3 Likes